Compare Pandas Datetimeindex To A Smaller Datetimeindex With Condition
I am trying to compare two Pandas DatetineIndexs with different lengths. I want to simply add a new column to my larger Dataframe (df) and place 1 where it matches the smaller Dat
Solution 1:
tEvents
and df.index
are different lengths. df.index == tEvents
looks to compare the two lists.
You want to check if an element in df.index
is in tEvents
. Thus replace df.index == tEvents
with df.index.isin(tEvents)
To see add a True or false value if date matches, use DataFrame.isin()
Post a Comment for "Compare Pandas Datetimeindex To A Smaller Datetimeindex With Condition"