Let's say we have a dataframe
with a 10 second interval timeseries.
We want to assign a value to a new column when:
- the minutes are 1 and 5 ( 00:01:00, 00:05:00)
- the seconds are 0, so that only the first row with minute 1 and 5 are considered
I'm already failing by filtering only two conditions, minute 1 and second 0:
df.something = np.where(df.index.second == 0 and df.index.minute == 1, 'some_value', np.nan)
this leads to an error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
If I use any()
or all()
in all combination it still doesn't work. Either nothing will be assigned to the column or all rows have 'some_value'
How to achieve this?
my desired output is:
datetime something
2022-02-01 00:00:50 NaN
2022-02-01 00:01:00 some_value
2022-02-01 00:01:10 NaN
2022-02-01 00:01:20 NaN
...
2022-02-01 00:04:50 NaN
2022-02-01 00:05:00 some_value
2022-02-01 00:05:10 NaN
....