From country Austria Belgium Denmark France Germany Italy Luxembourg Switzerland The Netherlands United Kingdom
Austria 0 0 0 0 0 0 3 0 6 1
Belgium 0 0 0 2 1 1 0 0 5 1
Denmark 0 2 0 2 0 1 0 2 3 0
France 0 0 0 0 6 0 0 0 4 0
Germany 0 2 0 6 0 0 0 1 1 0
Italy 0 0 3 0 1 0 4 1 1 0
Luxembourg 0 0 0 4 0 1 0 1 3 1
Switzerland 0 1 0 0 0 0 0 0 7 2
The Netherlands 1 0 5 1 0 2 0 0 0 1
United Kingdom 2 0 2 2 0 2 1 0 1 0
在这里我有一个表,其中的值是从一个国家分配给列上的一个国家的点。我总共有60个表,我试图创建一个最终的表,看起来相同,但值是所有60个表的平均值。我在pandas或stack exchange中的其他地方找不到任何函数可以像我正在尝试的那样平均每个值,如何处理这个问题
附言:在一些表格中,或多或少有一些国家
假设我们有一个数据帧列表
tables
我们将索引设置为
'From country'
,以防它还不是索引。如果已经是了,就跳过那部分然后我们将数据帧列表转换成
pd.Panel
,并取零轴上的平均值如果
tables
已经是一个字典,那么我们只需要将它直接传递给pd.Panel
可以先将^{} 与参数} 创建大} ,并聚合
sheetname=None
一起用于Dataframes
的dict
。然后通过^{df
,通过第二级index
创建^{mean
:编辑:
数据样本file:
如果有多个coutry,最后使用^{} 通过引用
index
和columns
名称进行过滤:相关问题 更多 >
编程相关推荐