Compare Two Pandas Dataframes And Update One, Depending On Results
I have the following (simplified) data; import pandas as pd a = [['10', '12345', '4'], ['15', '78910', '3'], ['8', '23456', '10']] b = [['10', '12345'], ['15', '78910'], ['9', '23
Solution 1:
This should do it
df_a.loc[(df_b['id'] == df_a['id']) & (df_a['sku'] == df_b['sku']), 'quantity '] = 0
Solution 2:
Another approach using pandas merge:
df_a.loc[pd.merge(df_a, df_b, on = ['id', 'sku'] , how='left',
indicator=True)['_merge'] == 'both', 'quantity'] = 0
df_a
id sku quantity
010123450115789100282345610
Post a Comment for "Compare Two Pandas Dataframes And Update One, Depending On Results"