dodo
dodo

Reputation: 21

Computing mean, median and mode in python

How to calculate central tendency (Median and mode) on pandas columns with Python 3, if the data has given with attribute Jumlah_individu?

this is my code to calculate mean (I have get it) but for median and mode I can't

Upvotes: 0

Views: 14479

Answers (3)

KevinCK
KevinCK

Reputation: 455

You can create a dictionary for the mean, median and mode

CentralTendacy = {}
CentralTendacy['Mean'] = df['Jumlah_individu'].mean()
CentralTendacy['Median'] = df['Jumlah_individu'].median()
CentralTendacy['Mode'] = df['Jumlah_individu'].mode()[0]

CentralTendacy

Upvotes: 0

xmindata
xmindata

Reputation: 105

Simply try data.describe() and you can get that list as shown in the pic

Upvotes: 5

helcode
helcode

Reputation: 2048

You can use .median() to get the middle value in a list.

ex. df['Jumlah_individu'].median()

You can use .mode() to get the highest frequency value in a list.

ex. df['Jumlah_individu'].mode()[0] where [0]to get the highest frequency value.

Upvotes: 7

Related Questions