728x90
반응형
In [1]:
import pandas as pd
In [2]:
raw_data_1 = {
'subject_id': ['1', '2', '3', '4', '5'],
'first_name': ['Alex', 'Amy', 'Allen', 'Alice', 'Ayoung'],
'last_name': ['Anderson', 'Ackerman', 'Ali', 'Aoni', 'Atiches']}
raw_data_2 = {
'subject_id': ['4', '5', '6', '7', '8'],
'first_name': ['Billy', 'Brian', 'Bran', 'Bryce', 'Betty'],
'last_name': ['Bonder', 'Black', 'Balwner', 'Brice', 'Btisan']}
raw_data_3 = {
'subject_id': ['1', '2', '3', '4', '5', '7', '8', '9', '10', '11'],
'test_id': [51, 15, 15, 61, 16, 14, 15, 1, 61, 16]}
In [5]:
data1 = pd.DataFrame(raw_data_1,columns=raw_data_1.keys())
data2 = pd.DataFrame(raw_data_2,columns=raw_data_2.keys())
data3 = pd.DataFrame(raw_data_3,columns=raw_data_3.keys())
In [7]:
data1.head()
Out[7]:
In [8]:
data2.head()
Out[8]:
In [9]:
data3.head()
Out[9]:
In [17]:
all_data = pd.concat([data1,data2],axis=0)
all_data
Out[17]:
In [18]:
all_data_col = pd.concat([data1,data2],axis=1)
all_data_col
Out[18]:
In [19]:
data3
Out[19]:
In [21]:
pd.merge(all_data,data3,on='subject_id')
Out[21]:
In [24]:
pd.merge(data1,data2,how='inner',on='subject_id')
Out[24]:
In [28]:
pd.merge(data1,data2,on='subject_id',how='outer')
Out[28]:
728x90
반응형