Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 多列平均_Python_Pandas_Dataframe - Fatal编程技术网

Python 多列平均

Python 多列平均,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个pandas数据帧,希望获得列方式的mean() 如下 A B C D 1 10 100 1000 10000 2 20 200 2000 20000 3 30 300 3000 30000 4 40 400 4000 40000 5 50 500 5000 50000 答复: A B C D 30 300 3000 30000 请建议一种方法。 我

我有一个pandas数据帧,希望获得列方式的
mean()
如下

    A    B    C      D
1   10  100 1000    10000
2   20  200 2000    20000
3   30  300 3000    30000
4   40  400 4000    40000
5   50  500 5000    50000
答复:

  A    B      C      D
  30  300   3000    30000
请建议一种方法。 我尝试了
df.mean()
和它的其他变体。

添加:

或:

或:


很高兴能帮上忙,天气真好!
print (df.mean().to_frame().T)
      A      B       C        D
0  30.0  300.0  3000.0  30000.0
print (pd.DataFrame(df.mean().values.reshape(1,-1), columns=df.columns))
      A      B       C        D
0  30.0  300.0  3000.0  30000.0
print (pd.DataFrame(np.mean(df.values, axis=0).reshape(1,-1), columns=df.columns))
      A      B       C        D
0  30.0  300.0  3000.0  30000.0