Nov-21-2018, 05:38 PM
Hi Ian,
How about the simple assignment line below:
a b e
0 11 15 9
1 12 20 8
2 13 30 7
3 14 20 6
4 15 30 5
5 16 50 4
your case above seems similar to what I'm doing and posted about earlier titled "DataFrame simple calculation" which I still have no answer/solution for, same calculation in the data frame (which is calculating the returns against each row/trade day.
In my case I am trying to assign the result to a new dataframe called [ret], but the results I get seem to always zero, see below applied your dataframe sample above:
0 NaN
1 0.0
2 0.0
3 0.0
4 0.0
5 NaN
Name: a, dtype: float64
How about the simple assignment line below:
df['e']=[9,8,7,6,5,4] dfOut[67]:
a b e
0 11 15 9
1 12 20 8
2 13 30 7
3 14 20 6
4 15 30 5
5 16 50 4
your case above seems similar to what I'm doing and posted about earlier titled "DataFrame simple calculation" which I still have no answer/solution for, same calculation in the data frame (which is calculating the returns against each row/trade day.
In my case I am trying to assign the result to a new dataframe called [ret], but the results I get seem to always zero, see below applied your dataframe sample above:
df = pd.DataFrame({"a": [11,12,13,14,15,16], "b": [15,20,30,20,30,50]}) ret=(df.a[1:]-df.a[:-1])/df.a[:-1] retOut[63]:
0 NaN
1 0.0
2 0.0
3 0.0
4 0.0
5 NaN
Name: a, dtype: float64