Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

median python code

import statistics

list_one = [1,2,3,4,5,6]

x = statistics.median(list_one)

print(x)
Comment

median in python

import statistics

statistics.median(list_name)
Comment

get median using python

# --------------------- MEDIAN ---------------------

# Dataset for questions -
dataset = [2, 1, 1, 4, 5, 8, 12, 4, 3, 8, 21, 1, 18, 5]

# Finding length of dataset
lenOfDataset = len(dataset)

# Sorting dataset in ascending order
dataset.sort()

# checking the numbers if its even or odd by checking their remainders
# If the number is even, we find 2 middle elements in a list and get their average to print it out
# But if the number is odd, we find the middle element in a list and print it out.
if lenOfDataset % 2 == 0:
    median1 = dataset[lenOfDataset//2]
    median2 = dataset[lenOfDataset//2 - 1]
    median = (median1 + median2)/2
else:
    median = dataset[lenOfDataset//2]

# Printing the median of dataset
print(median)
Comment

PREVIOUS NEXT
Code Example
Python :: convert torch to numpy 
Python :: parameter grid 
Python :: bisect_left in python 
Python :: django create model from dictionary 
Python :: ready command discord.py 
Python :: how to make a forever loop in python 
Python :: numpy print options 
Python :: python read text file look for string 
Python :: python image to video 
Python :: python to golang 
Python :: pandas groupby histogram 
Python :: trimming spaces in string python 
Python :: how to find duplicate numbers in list in python 
Python :: pandas find basic statistics on column 
Python :: python numpy kurtosis 
Python :: python format decimal 
Python :: openpyxl add worksheet 
Python :: Get all columns with particular name in string 
Python :: use of // in python 
Python :: python set a specific datetime 
Python :: python read from txt file 
Python :: argparse list 
Python :: find allurl in text python 
Python :: python list of all tkinter events 
Python :: python run as service windows 
Python :: date to day python 
Python :: except as exception: 
Python :: how to import .csv file in python 
Python :: python df select first x columns 
Python :: pandas strips spaces in dataframe 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =