I have the following Pandas DataFrame df:
name rating val1 val2 val3
<DATE>
2020-10-16 cool_name 23.0 1.700079 1.515385 0.184694
2020-10-19 cool_name -3.0 1.230071 1.289615 -0.059545
2020-10-20 cool_name -11.0 0.007064 0.675135 -0.668071
2020-10-21 cool_name -21.0 -2.093643 -0.408622 -1.685021
2020-10-22 cool_name -5.0 -2.384278 -0.638191 -1.746087
How can I add a new column called "calculated" which is calculated this way:
df['calculated'] = df['calculated'(previous day)] + df['val3'(current day)]
If I try to do it this way, I'll receive a key error (I am not even sure if it is shift(1) or shift(-1)):
df['calculated'] = df['calculated'].shift() + df['val3']
I think this is due to the fact that the first row doesn't have a previous row with "calculated" . Howerver, I don't know how to solve this problems.
I tried various solutions and searched for answers, but unfortunately I'm stuck. Any help would be highly appreciated.