How to subtract rows of one pandas data frame from another?

后端 未结 4 1189
执笔经年
执笔经年 2020-12-10 11:26

The operation that I want to do is similar to merger. For example, with the inner merger we get a data frame that contains rows that are present in the first AN

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-10 12:10

    Consider Following:

    1. df_one is first DataFrame
    2. df_two is second DataFrame

    Present in First DataFrame and Not in Second DataFrame

    Solution: by Index df = df_one[~df_one.index.isin(df_two.index)]

    index can be replaced by required column upon which you wish to do exclusion. In above example, I've used index as a reference between both Data Frames

    Additionally, you can also use a more complex query using boolean pandas.Series to solve for above.

提交回复
热议问题