2024-04-26 01:15:55 发布
网友
我有50个数据帧和一个结构,但值是不同的。如何从这些数据中获得平均数据帧?你知道吗
active nodes graph 0 128 1 128 2 128 3 127 4 126 5 126 6 126 7 126 8 126 9 125 10 124
将所有数据帧添加到一个列表中,连接它们并计算每行的平均值:
dfs = [df1, df2, ... dfn] pd.concat(dfs, axis=1).mean(axis=1)
改用numpy。你知道吗
numpy
假设数据帧列表dfs
dfs
dfs = [pd.DataFrame(np.random.randint(10, size=(10, 10))) for _ in range(50)]
然后用np.concatenate计算平均值,然后取mean。但是作为numpy这也应该更快。你知道吗
np.concatenate
mean
pd.Series(np.concatenate([df.values for df in dfs], axis=1).mean(1), dfs[0].index) 0 4.472 1 4.722 2 4.644 3 4.574 4 4.624 5 4.446 6 4.548 7 4.606 8 4.440 9 4.442 dtype: float64
计时
将所有数据帧添加到一个列表中,连接它们并计算每行的平均值:
改用
numpy
。你知道吗假设数据帧列表
dfs
然后用
np.concatenate
计算平均值,然后取mean
。但是作为numpy
这也应该更快。你知道吗计时
相关问题 更多 >
编程相关推荐