首页 > 解决方案 > python中每15行数据框的平均值

问题描述

我有一个(1500x11)的数据框。我必须选择 15 行中的每一行并分别取每 11 列的平均值。所以我的最终数据框的尺寸应该是 100x11。如何在 Python 中做到这一点。

标签: pythondataframemean

解决方案


The following should work:

dfnew=df[:0]
for i in range(100):
    df2=df.iloc[i*15:i*15+15, :]
    x=pd.Series(dict(df2.mean()))
    dfnew=dfnew.append(x, ignore_index=True)

print(dfnew)

推荐阅读