Python中数据框的各列的多个函数

时间:2017-12-05 20:03:45

标签: python function pandas dataframe

如何在一行代码中应用函数,如下所示。我想计算以下共享链接的数据集的均值,STD等。在给定的例子中,我已经计算了“mean”,现在我想添加一些代码并找到其他函数,如STD等。

df1 = df.loc[(df.time>=171) & (df.time<=174)[['S08','S09','S41']].mean(axis=1)

click here for the dataset (CSV file) i am referring to the column names

enter image description here

在上图中,我需要均值和STD(蓝色),但在不同的数据帧中不相同。

1 个答案:

答案 0 :(得分:1)

试试这个:

In [24]: df.loc[(df.time>=171) & (df.time<=174),['S08','S09','S41']].T.agg(['mean','std']).T
Out[24]:
           mean       std
17131  1.014278  0.007357
17132  1.010441  0.005698
17133  1.008947  0.006189
17134  1.006198  0.008981
17135  1.003360  0.012050
17136  1.002270  0.012952
17137  1.000827  0.014543
17138  0.999155  0.010764
17139  0.998330  0.010462
17140  0.996994  0.009813
...         ...       ...
17421  1.005489  0.068211
17422  1.054022  0.126477
17423  1.109993  0.174473
17424  1.143518  0.192038
17425  1.143594  0.168867
17426  1.126942  0.117057
17427  1.088270  0.080759
17428  1.046547  0.053798
17429  1.005698  0.025103
17430  0.981894  0.027097

[300 rows x 2 columns]