-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpd_merge.py
23 lines (17 loc) · 852 Bytes
/
pd_merge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import numpy as np
import pandas as pd
df1 = pd.DataFrame({'employee': ['Bob', 'Jake', 'Lisa', 'Sue'],
'group': ['Accounting', 'Engineering', 'Engineering', 'HR']})
df2 = pd.DataFrame({'employee': ['Lisa', 'Bob', 'Jake', 'Sue'],
'hire_date': [2004, 2008, 2012, 2014]})
df3 = pd.merge(df1, df2)
df4 = df4 = pd.DataFrame({'group': ['Accounting', 'Engineering', 'HR'],
'supervisor': ['Carly', 'Guido', 'Steve']})
print("created data frames: "); print(df1); print(df2); print(df4)
print("created by merging df1, df2"); print(df3)
print("Many to one pd.merge(df3, df4)");print(pd.merge(df3, df4))
print("Many to Many joins")
df5 = pd.DataFrame({'group': ['Accounting', 'Accounting',
'Engineering', 'Engineering', 'HR', 'HR'], 'skills': ['math', 'spreadsheets', 'coding', 'linux',
'spreadsheets', 'organization']})
print(df5); print(pd.merge(df1, df5))