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 :: python range in intervals of 10 
Python :: maximum element in dataframe row 
Python :: how to make your own range function in python 
Python :: no module named googlesearch 
Python :: pandas show full columns 
Python :: sqlite operational error no such column 
Python :: set python 3 as default mac 
Python :: sub matrix python 
Python :: how to kill a script if error is hit python 
Python :: python how to play mp3 file 
Python :: how to get the index of the first integer in a string python 
Python :: selenium get h1 text python 
Python :: python list of whole numbers 
Python :: torch.load 
Python :: django media url 
Python :: how to filter queryset with foreign key in django 
Python :: delete last message discord.py 
Python :: change the number in 3rd line to get factorial for the number you want. Ex: num = 30 
Python :: How to get the date from week number in Python? 
Python :: shallow copy in python 
Python :: swapping variables in python 
Python :: python line break inside string 
Python :: make a new environment conda 
Python :: dicttoxml python? 
Python :: weighted average in python pandas 
Python :: tkinter python 
Python :: discord.py message user 
Python :: how to install python library 
Python :: how to get mac address in python 
Python :: python for in for in 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =