Skip to content
Advertisement

For each date – is it between any of the provided date bounds?

Data:

df:

JavaScript

df_cal:

JavaScript

Expected result:

JavaScript

Goal:

I want to assign values to a new column col: to 1 if df.index is between any of df_cal date ranges, and to 0 otherwise.

Reference:

I refer this post. But it just works for one condition and mine is lots of date ranges. And I don’t want to use dataframe join method to achieve it because it will break index order.

Advertisement

Answer

You check with numpy broadcasting

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement