pandas get rows which are NOT in other dataframe

后端 未结 13 1140
春和景丽
春和景丽 2020-11-22 02:17

I\'ve two pandas data frames which have some rows in common.

Suppose dataframe2 is a subset of dataframe1.

How can I get the rows of dataframe1 which

13条回答
  •  独厮守ぢ
    2020-11-22 02:52

    extract the dissimilar rows using the merge function

    df = df.merge(same.drop_duplicates(), on=['col1','col2'], 
                   how='left', indicator=True)
    
    save the dissimilar rows in CSV
    df[df['_merge'] == 'left_only'].to_csv('output.csv')
    

提交回复
热议问题