1.merge

def merge(left, right, how="inner", on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=False, suffixes=("_x", "_y"), copy=True, indicator=False, validate=None):
    left: 拼接的左侧DataFrame对象
    right: 拼接的右侧DataFrame对象
    on: 要加入的列或索引级别名称. 必须在左侧和右侧DataFrame对象中找到. 如果未传递且left_index和right_index为False,则DataFrame中的列的交集将被推断为连接键
    left_on:左侧DataFrame中的列或索引级别用作键. 可以是列名,索引级名称,也可以是长度等于DataFrame长度的数组
    right_on: 左侧DataFrame中的列或索引级别用作键. 可以是列名,索引级名称,也可以是长度等于DataFrame长度的数组
    left_index: 如果为True,则使用左侧DataFrame中的索引(行标签)作为其连接键. 对于具有MultiIndex(分层)的DataFrame,级别数必须与右侧DataFrame中的连接键数相匹配
    right_index: 与left_index功能相似
    how: One of 'left', 'right', 'outer', 'inner'. 默认inner.inner是取交集,outer取并集.比如left:['A','B','C'];right[''A,'C','D'];inner取交集的话,left中出现的A会和right中出现的买一个A进行匹配拼接,如果没有是B,在right中没有匹配到,则会丢失.'outer'取并集,出现的A会进行一一匹配,没有同时出现的会将缺失的部分添加缺失值
    sort: 按字典顺序通过连接键对结果DataFrame进行排序. 默认为True,设置为False将在很多情况下显着提高性能
    suffixes: 用于重叠列的字符串后缀元组. 默认为('x',' y')
    copy: 始终从传递的DataFrame对象复制数据(默认为True),即使不需要重建索引也是如此
    indicator:将一列添加到名为_merge的输出DataFrame,其中包含有关每行源的信息. _merge是分类类型,并且对于其合并键仅出现在“左”DataFrame中的观察值,取得值为left_only,对于其合并键仅出现在“右”DataFrame中的观察值为right_only,并且如果在两者中都找到观察点的合并键,则为left_only


DataFrame1 = pd.DataFrame(np.arange(20).reshape(4, 5), columns=['a', 'b', 'c', 'd', 'e'], index=['one', 'two', 'three', 'four'])
print(DataFrame1)
DataFrame2 = pd.DataFrame(np.arange(42).reshape(6, 7), columns=['a', 'b', 'c', 'd', 'e', 'f', 'g'], index=['one', 'two', 'three', 'four', 'five', 'six'])
print(DataFrame2)
print(pd.merge(DataFrame1, DataFrame2, on=['b', 'c'], how='left'))