Date | COL_1 | COL_2 |
---|---|---|
2017-04-21 | 0.0 | NaN |
2017-04-24 | 1.0 | 0.0 |
2017-04-25 | 0.0 | -1.0 |
Have the following table in datetime index.
What's the best way do I put in a conditional statement to filter where if COL_1 of the earliest index date is 0, COL_2 of the earliest index date, (Nan), is set to -1.
Need to keep it dynamic and filter without mentioning the specific dates.
Thanks!
CodePudding user response:
IIUC:
df.loc[(df.index == df.index.min()) & (df['COL_1'] == 0), 'COL_2'] = -1
print(df)
# Output
COL_1 COL_2
2017-04-21 0.0 -1.0
2017-04-24 1.0 0.0
2017-04-25 0.0 -1.0