Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python mode

from scipy import stats
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
x = stats.mode(speed)
print(x)
Comment

get mode using python

# --------------------- MODE ---------------------

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

# Sorting dataset in ascending order
dataset.sort()

# Creating an empty list to append the occurrence of each number
myList = []

# Counting the occurrence of each number
i = 0
while i < len(dataset) :
	myList.append(dataset.count(dataset[i]))
	i += 1

# Creating a dictionary for K : V, K = values of sorted dataset, V = occurrence of each number in dataset
myDict = dict(zip(dataset, myList))

# Now we have to differentiate the k values with the highest v values
myDict2 = {k for (k,v) in myDict.items() if v == max(myList) }

# Printing the mode of dataset
print(myDict2)
Comment

PREVIOUS NEXT
Code Example
Python :: snake water gun game in python 
Python :: python library for downsampling a photo 
Python :: sort a dictionary by value then key 
Python :: dict in dict in python 
Python :: python os.remove permissionerror winerror 5 access is denied 
Python :: python not equal to symbol 
Python :: make value of two tables unique django 
Python :: hist pandas 
Python :: print binary tree python 
Python :: python isin 
Python :: python indentation 
Python :: python to linux executable 
Python :: circular cropping of image in python 
Python :: change column names pandas 
Python :: pandas filter column with or 
Python :: python print string and variable 
Python :: datetime print the current time 
Python :: django class based views 
Python :: move files in python 
Python :: numpy arange float step 
Python :: catch exception python unittest 
Python :: switch case dictionary python 
Python :: how to generate list in python 
Python :: check if a file exists in python 
Python :: python how to use logarithm 
Python :: re.search() python 
Python :: dicionario python 
Python :: concatenating strings 
Python :: python type hint list of possible values 
Python :: 2d array row and column 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =