唯一的重点是:join函数默认将两个DataFrame的index进行合并
import pandas as pd
index=pd.date_range('2020-6-13', periods=5)
index
##output##
DatetimeIndex(['2020-06-13', '2020-06-14', '2020-06-15', '2020-06-16', '2020-06-17'],
dtype='datetime64[ns]', freq='D')
df1 = pd.DataFrame({'lkey': ['foo', 'bar', 'baz', 'foo'],
'lkey2': ['foo', 'bar', 'baz', 'foo'],
'value1': [1, 2, 3, 5]},index=index[:4])
df1.index.name = 'date'
df1
.
df2 = pd.DataFrame({'rkey': ['foo', 'bar', 'baz', 'foo','sea'],
'rkey2': ['foo', 'bar', 'baz', 'foo','sea'],
'value2': [5, 6, 7, 8, 9]},index=index[:5])
df2
.
df2.join(df1[['value1']])