我有一個 2000 列和 1 行的資料框。我想一次計算 50 列的 STD。關于如何做的任何想法?
謝謝你,
uj5u.com熱心網友回復:
如果需要計算前 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/493221.html
