I have a dataframe with two columns 'a' and 'b' where 'b' is the difference between the value of 'a' and the previous value 'a'
df = pd.DataFrame({'a': [10, 60, 30, 80, 10]})
df['b'] = df['a']-df['a'].shift(1)
a b
0 10 NaN
1 60 50.0
2 30 -30.0
3 80 50.0
4 10 -70.0
I want to create a new column 'c' with values as a list of previous value of 'a' and the current value of 'a' (example, [60,30]) only where the column 'b' is negative. Otherwise it has to be a list of the current value 'a' itself.
The resulting output should look like
a b c
0 10 NaN [10]
1 60 50.0 [60]
2 30 -30.0 [60, 30]
3 80 50.0 [80]
4 10 -70.0 [80, 10]