简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM