Skip to content

Instantly share code, notes, and snippets.

@eLtronicsVilla
Created February 28, 2019 13:40
Show Gist options
  • Save eLtronicsVilla/30a3e3c4272bad75532dceea09c48573 to your computer and use it in GitHub Desktop.
Save eLtronicsVilla/30a3e3c4272bad75532dceea09c48573 to your computer and use it in GitHub Desktop.
Calculation of mode on given data set
# sample code to calculate the mode of given data set
from collections import Counter
d_set = [1,3,3,4,5,7,8,9]
def mode(data):
# return a list might be more than one mode
c = Counter(data) # count occurance of the each item
max_count = max (c.values()) # find out max value in data
return [x_i for x_i , count in c.iteritems() if count == max_count ]
mode(d_set)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment