Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding median of entire pandas Data frame

Tags:

python

pandas

I'm trying to find the median flow of the entire dataframe. The first part of this is to select only certain items in the dataframe.

There were two problems with this, it included parts of the data frame that aren't in 'states'. Also, the median was not a single value, it was based on row. How would I get the overall median of all the data in the dataframe?

like image 463
ksalerno Avatar asked Apr 27 '17 19:04

ksalerno


1 Answers

Two options:

1) A pandas option:

df.stack().median()

2) A numpy option:

np.median(df.values)
like image 78
ayhan Avatar answered Oct 06 '22 07:10

ayhan