'Replacing .loc method of pandas

When I try this statement, I get an error...

spy_daily.loc[fomc_events.index, "FOMC"] = spy_daily.loc[fomc_events.index, "days_since_fomc"]

KeyError: "Passing list-likes to .loc or [] with any missing labels is no longer supported. The following labels were missing: DatetimeIndex(['2020-03-15', '2008-03-16'], dtype='datetime64[ns]', name='Date', freq=None). 

Not sure how to correct it. The complete code is available here...

https://www.wrighters.io/analyzing-stock-data-events-with-pandas/



Solution 1:[1]

Try to convert your index from your other dataframe to a list to subsetting your first dataframe:

rows = fomc_events.index.tolist()
spy_daily.loc[rows, "FOMC"] = spy_daily.loc[rows, "days_since_fomc"]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Corralien