I am new to python and pandas, and I was wondering if there was a 'pythonic' way to accomplish the following: I have a dataframe that looks like this:
L1 L2 L3
X 1 50
X 2 100
Z 1 15
X 3 200
Z 2 10
Y 1 1
Z 3 20
Y 2 10
Y 3 100
And I am trying to order the rows and create an additional column that showscumulative values derived from L3 in ascending order. The output I need is the following:
L1 L2 L3 New
X 3 200 0.40000
X 2 100 0.60000
X 1 200 1.00000
Y 3 100 0.90090
Y 2 10 0.99099
Y 1 1 1.00000
Z 3 20 0.44444
Z 1 15 0.77778
Z 2 10 1.00000
The value in row 1 (0.4000) under "New" represents 200/500 (the sum of al L3 values for L1). The second value (0.6000) is simply 300/500 and so on. The 'loop' is repeated for each value of X, Y and Z.
Can anybody help with this? Thank you.