import pandas as pd
import numpy as np
from pandas import Series, DataFrame
df1 = DataFrame({'key':['X','Y','Z'], 'data_set_1':[1,2,3]})
df1
Out[5]:
data_set_1 key
0 1 X
1 2 Y
2 3 Z
df2 = DataFrame({'key':['A','B','C'], 'data_set_2':[4,5,6]})
df2
Out[7]:
data_set_2 key
0 4 A
1 5 B
2 6 C
# 没有相同的列值
pd.merge(df1,df2)
Out[8]:
Empty DataFrame
Columns: [data_set_1, key, data_set_2]
Index: []
# 默认合并
df2 = DataFrame({'key':['X','B','C'], 'data_set_2':[4,5,6]})
pd.merge(df1,df2)
Out[10]:
data_set_1 key data_set_2
0 1 X 4
df1 = DataFrame({'key':['X'