I have a DataFrame like this:
DataFrame
df:
df
fruit val1 val2 0 orange 15 3 1 apple 10 13 2 mango 5 5 >
fruit val1 val2 0 orange 15 3 1 apple 10 13 2 mango 5 5
It's a good answer, but written in 2014. I just modified a little bit, so it can pass the compiler and results looks similar to the example.
df['cum_sum'] = df["val1"].cumsum() df['cum_perc'] = round(100*df.cum_sum/df["val1"].sum(),2)