27
我有一個DataFrame
這樣的:列的累積總數和百分比?
df
:
fruit val1 val2
0 orange 15 3
1 apple 10 13
2 mango 5 5
如何讓熊貓給我的累加值和百分比列只val1
?
所需的輸出:
df_with_cumsum
:
fruit val1 val2 cum_sum cum_perc
0 orange 15 3 15 50.00
1 apple 10 13 25 83.33
2 mango 5 5 30 100.00
我試過df.cumsum()
,但它給我這個錯誤:
TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
'TypeError:不支持的操作數類型爲*:'int'和'instancemethod''爲第二行 – ComputerFellow
您是否輸入'cumsum'或'cum_sum'? – BrenBarn
哦,你的天才! – ComputerFellow