I have a DataFrame
like this:
df
:
fruit val1 val2
0 orange 15 3
1 apple 10 13
2 mango 5 5
How do I get Pandas to give me a cumulative sum and percentage column on only val1
?
Desired output:
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
I tried df.cumsum()
, but it's giving me this error:
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''
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…