【问题标题】:finding the average and std across multiple Pandas series找到多个 Pandas 系列的平均值和标准
【发布时间】:2021-11-03 07:04:24
【问题描述】:

我有一个(比如说 100 个)对象的列表,每个对象都包含一个熊猫系列。所有系列数据都具有相同的长度(比如说 400)。我想计算平均值和系列数据,以便获得两个系列,与另一个系列 (400) 大小相同。

有没有捷径可以做到这一点?

【问题讨论】:

    标签: python pandas series standard-deviation


    【解决方案1】:

    您需要通过concat 将它们连接在一起并使用DataFrame.agg

    s1 = pd.Series(range(3))
    s2 = pd.Series([4,5,7])
    s3 = pd.Series([7,5,2])
    
    L = [s1, s2, s3]
    
    df = pd.concat(L, axis=1).agg(['mean','std'], axis=1)
    print (df)
           mean       std
    0  3.666667  3.511885
    1  3.666667  2.309401
    2  3.666667  2.886751
    

    print (df['mean'])
    0    3.666667
    1    3.666667
    2    3.666667
    Name: mean, dtype: float64
    
    print (df['std'])
    0    3.511885
    1    2.309401
    2    2.886751
    Name: std, dtype: float64
    

    【讨论】:

      猜你喜欢
      • 2019-08-15
      • 1970-01-01
      • 2019-01-01
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 2018-06-26
      • 2018-09-08
      相关资源
      最近更新 更多