Удалить общие наблюдения - PullRequest
0 голосов
/ 30 апреля 2020

У меня есть 2 кадра данных

Map3 = pd.DataFrame({
"partner_country": ["France","France","France","France","France","France",
                     "Spain","Spain","Spain","Spain","Spain","Spain"
                    ],

"my_network": ["Ireland","Austria",None,"Sweden","Italy",None , #France
               "Ireland","Austria","Denmark","Sweden",None,"United Kingdom" #Spain
               ]})#Netherlands

Map4 = pd.DataFrame({
"partner_country": ["France","France","France","France","France","France",
                     "Spain","Spain","Spain","Spain","Spain","Spain"
                    ],

"my_network": [None,None,None,None,"Italy",None , #France
               None,"Austria",None,"Sweden",None,"United Kingdom" #Spain
               ]})#Netherlands

Я хочу удалить все наблюдения, обычные для Map3 и Map4, из фрейма данных Map3. Попробовал следующий код:

Map4[~(Map4['partner_country'].isin(Map3['partner_country'])Map4['my_network'].isin(Map3['my_network']]

1 Ответ

1 голос
/ 30 апреля 2020

Простое решение, поскольку у вас есть только 2 столбца, может быть:

common = (Map3.partner_country + Map3.my_network).isin(Map4.partner_country + Map4.my_network)
Map3 = Map3.loc[~common]
...