user2512443
user2512443

Reputation: 473

Remove a set of dates from dataframe

Given a data frame that has a list of dates, I want to remove dates from the second data frame.

For example:

df1 with list of dates:

      day              
0  2021-02-14      
1  2021-02-15      
2  2021-02-16          
3  2021-02-18        
4  2021-02-20    
5  2021-03-17      

df2:

      day           X1   X2
 0  2021-02-14      1    2
 1  2021-02-15      1    3
 2  2021-02-16      2    1
 3  2021-02-17      3    2
 4  2021-02-18      4    3
 5  2021-02-19      5    4
 6  2021-02-20      2    6
 7  2021-03-17      6    7

Desired outcome:

     day           X1   X2
3  2021-02-17      3    2
5  2021-02-19      5    4

Upvotes: 0

Views: 52

Answers (1)

wwnde
wwnde

Reputation: 26686

Mask .isin()

df2[~(df2['day'].isin(df1['day']))]

Upvotes: 3

Related Questions