问题描述:

I have a distance matrix in hand where I would like to get its max,min, mean, median, etc. values; expected describe() to do it for me, but looks like I was wrong. Both from scipy.stats import describe and df.describe() work either on columns or rows.

What might be other approaches than calling each method separately?

网友答案:

Convert the 2-D DataFrame to a 1-D Series:

series = pd.Series(df.values.ravel())

Then call series.describe().


For example,

In [24]: df  = pd.DataFrame(np.random.random((5,4)))

In [25]: series = pd.Series(df.values.ravel())

In [26]: series.describe()
Out[26]: 
count    20.000000
mean      0.514002
std       0.332819
min       0.001209
25%       0.298695
50%       0.528073
75%       0.804711
max       0.973840
dtype: float64
相关阅读:
Top