2
ID count cum Count
1 10 70
2 20 50
3 40 40
パンダでこれを行うにはどのように任意のアイデアを実現するため
ID count
1 10
2 20
3 40
だから、累積カウントに、私がしたい以下のようにサンプルデータフレームを持っていますか?
ID count cum Count
1 10 70
2 20 50
3 40 40
パンダでこれを行うにはどのように任意のアイデアを実現するため
ID count
1 10
2 20
3 40
だから、累積カウントに、私がしたい以下のようにサンプルデータフレームを持っていますか?
使用スワップ注文の[::-1]
ダブル:
df['cum Count'] = df['count'].iloc[::-1].cumsum().iloc[::-1]
print (df)
ID count cum Count
0 1 10 70
1 2 20 60
2 3 40 40
numpyのソリューション:
df['cum Count'] = df['count'].values[::-1].cumsum()[::-1]
print (df)
ID count cum Count
0 1 10 70
1 2 20 60
2 3 40 40
出力は正しいですか? 「50」は「60」ではない? – jezrael