Reputation: 177
I have an auditing script that takes a sample from an excel file. The code work just fine, but I'm trying to make a comparison between two dataframes, the initial one and the sampled one, and mark items as "Audit" in the original frame. I've used both codes below to no success:
df['Retailer Item ID'] in final['Retailer Item ID'], df['Track Item'] =
'Audit'
if df.loc[df['Retailer Item ID'] == final['Retailer Item ID']:
df['Track Item'] = 'Audit']
Any idea what I'm doing wrong?
Upvotes: 0
Views: 65
Reputation: 1049
You can do a merge and pass the indicator as a parameter:
df_merged=pd.merge(df,final,left_on='Track Item', right_on='Retailer Item ID', how='left',indicator=True)
You will see a "True" value in the indicator column for each item that you want to include in your audit sample.
Upvotes: 0
Reputation: 177
Solution: df.loc[df['Retailer Item ID'].isin(final['Retailer Item ID']), 'Track Item'] = 'Audit'
Upvotes: 0