python - Return a pandas DataFrame when using pandas.DataFrame.mean -
the function pandas.dataframe.mean
returns pandas.series
. return dataframe same column names original dataframe. how 1 this?
import numpy np, pandas pd df = pd.dataframe(np.random.rand(10,5), columns = ['a', 'b', 'c', 'd', 'e'])
this returns pandas.series object
df.mean()
so this
df.mean(level = 0)
and this
df.mean(axis = 0)
the current way using following commands, easiest way it?!
means = df.mean(axis = 0) pd.dataframe(means).t
i hoping more straight-forward solution!
you using to_frame
, transpose:
in [188]: df.mean().to_frame().t out[188]: b c d e 0 0.393221 0.441338 0.445528 0.67516 0.699105
Comments
Post a Comment