如何计算Python中两个数据帧列表中所有对应元素的均值和标准差?

How to compute the mean and standard deviation of all the corresponding elements in the list of two dataframes in Python?

我有一个包含两个数据框的列表,比如 df1 和 df2。下面给出df1和df2,

df1 = and df2 =

此外,listOfDataframe = [df1,df2]

df1和df2可以生成如下,

df1 = pd.DataFrame(np.array([[99,85,93], [89,97,94], [80,95,89]]), index=["A", "B", "C"], columns = ["Sensetivity", "specificity", "Accuracy"]) 
df2 = pd.DataFrame(np.array([[85,99,50], [97,89,75], [95,80,60]]), index=["A", "B", "C"], columns = ["Sensetivity", "specificity", "Accuracy"])

现在,我想计算位于列表 listOfDataframe 中的两个数据框中相应元素的均值和标准差。我们如何以简单的方式做到这一点?我想要一个单一的输出数据框如下,

输出=

提前致谢!

让我们试试:

listOfDataframe = [df1,df2]
stats = (pd.concat(listOfDataframe).groupby(level=0).agg(['mean','std'])
           .swaplevel(0,1,axis=1)
           .round(0).astype(str)   # modify this as you wish
        )

out = stats['mean'] + '±' + stats['std']

输出:

  Sensetivity specificity   Accuracy
A   92.0±10.0   92.0±10.0  72.0±30.0
B    93.0±6.0    93.0±6.0  84.0±13.0
C   88.0±11.0   88.0±11.0  74.0±21.0