Sunday, April 22, 2018

Merging and Joining in Pandas

import pandas as pd
week1 = pd.read_csv('Restaurant - Week 1 Sales.csv')

len(week1),len(week2)
pd.concat([week1,week2],ignore_index=True)
sales = pd.concat([week1,week2],keys=['Week1','Week2'])
sales.ix[('Week2',240),'Customer ID']
sales = week2.append(week1,ignore_index=True)
sales.info()
week1.merge(week2,how='inner', on='Customer ID',suffixes=['_wk1','_wk2'])

week1.merge(week2,how='inner', on=['Customer ID','Food ID'],suffixes=['_wk1','_wk2'])
merged = week1.merge(week2,how='outer', on='Customer ID',suffixes=['_wk1','_wk2'],indicator=True)
merged['_merge'].value_counts()
mask = merged['_merge'].isin(['left_only','right_only'])
merged[mask]

week1.join(week1_survey,how='inner', on='OrderID')

No comments:

Post a Comment