Alfonso_MA
Alfonso_MA

Reputation: 555

Drop from datetime index dataframe rows based in year month day from another dataframe

I have one dataframe like the following:

                       A     
2014-06-02 09:00:00   ...
2014-06-02 10:00:00   ...
2014-06-02 11:00:00   ...
2014-06-02 12:00:00   ...

2014-06-03 09:00:00   ...
2014-06-03 10:00:00   ...

2014-06-04 11:00:00   ...
2014-06-04 12:00:00   ...

2014-06-05 11:00:00   ...
2014-06-05 12:00:00   ...

And another like the following

                       A
2014-06-03 13:14:00   ...
2014-06-04 16:33:00   ...

I need one dataframe like the following :

                       A
2014-06-02 09:00:00   ...
2014-06-02 10:00:00   ...
2014-06-02 11:00:00   ...
2014-06-02 12:00:00   ...
2014-06-05 11:00:00   ...
2014-06-05 12:00:00   ...

That is: Drop from the first dataframe every row having year-month-day in the second dataframe

Upvotes: 0

Views: 40

Answers (1)

Scott Boston
Scott Boston

Reputation: 153460

You could use floor, and ~(invert symbol), and check to see if index of dfb isin dfa:

dfa[~dfa.index.floor('D').isin(dfb.index.floor('D'))]

Note both indexes need to be datetime dtypes.

Upvotes: 2

Related Questions