我有一个 2000 列和 1 行的数据框。我想一次计算 50 列的 STD。关于如何做的任何想法?
谢谢你,
如果需要计算前 50 列,请使用:
out = df.iloc[0, :50].std()
对于每 50 个值,请使用:
s = df.iloc[0]
out = s.groupby(np.arange(len(s)) // 50).std()
样品:
np.random.seed(202206)
df = pd.DataFrame([np.random.randint(20, size=20)]).add_prefix('c')
print(df)
c0 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 \
0 7 8 12 15 2 10 3 3 6 7 5 19 1 10 15 12 15
c17 c18 c19
0 9 18 10
out = df.iloc[0, :5].std()
print(out)
4.969909455915671
s = df.iloc[0]
out = s.groupby(np.arange(len(s)) // 5).std()
print(out)
0 4.969909
1 2.949576
2 7.280110
3 3.701351
Name: 0, dtype: float64
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句