I have a dataframe in pandas. One of its columns is called 'upperband'
, and this column is full of values (type: numpy.float64). I have the following line inside of an if statement:
dataframe['upperband'][current] = dataframe['upperband'][current-1]
, where current
is going from 1 too the length of the dataframe. The code inside this if statement, executes well, but dataframe['upperband'][current]
will not change to the new value whatsoever. It only remains the same as the old value.
More to that, I have 2 different codes with the same piece of code, and one of them is working and the other one doesn't work. How can I fix this? This doesn't make any sense.
Minimal reproductible example: Initial dataframe:
upperband
0 1330
1 1350
2 1380
3 1360
4 1300
5 1290
current goes from 0 to 5, and when the dataframe['upperband'][current] > dataframe['upperband'][current-1]
, i want the dataframe['upperband'][current]
value to be the same as dataframe['upperband'][current-1]
. In this case, when current = 3, i want the dataframe['upperband'][current]
to be 1380
(the previous value, since the current value > previous value)
Expected result:
upperband
0 1330
1 1350
2 1380
3 1380
4 1380
5 1380
The result i get: the same as initial dataframe