Median of pandas dataframe column
If you're looking for how to calculate the Median Absolute Deviation -
In [1]: df['dist'] = abs(df['count'] - df['count'].median())In [2]: dfOut[2]: name count dist0 aaaa 2000 11001 bbbb 1900 10002 cccc 900 03 dddd 500 4004 eeee 100 800In [3]: df['dist'].median()Out[3]: 800.0
for a column could also be calculated using statsmodels.robust.scale.mad
, which can also be passed a normalization constant c
which in this case is just 1.
>>> from statsmodels.robust.scale import mad>>> mad(df['count'], c=1)800.0