pandas provides various facilities for easily combining together Series, DataFrame, and Panel objects with various kinds of set logic for the indexes and relational algebra functionality in the case of join / merge-type operations.
1、merge
pd.merge(left, right, how='inner', on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=True, suffixes=('_x', '_y'), copy=True, indicator=False)
left ︰ 對象
right ︰ 另一個 對象
on︰ 要 加入 的 列 (名稱) 。 必須 在 左 、 右 綜合 對象 中 找到 。 如果 不 能 通過 left_index 和 right_index 是 假 , 將 推斷 DataFrames 中 的 列 的 交叉點 為 連接 鍵
left_on ︰ 從 左邊 的 綜合 使用 作為 鍵 列 。 可以 是 列名 或 數組 的 長度 等於 長度 綜合
right_on ︰ 從 正確 的 綜合 , 以 用作 鍵 列 。 可以 是 列名 或 數組 的 長度 等於 長度 綜合
left_index ︰ 如果為 True , 則 使用 索引 (行 標簽) 從 左 綜合 作為 其 聯接 鍵。 在 與 多重 (層次) 的 綜合 , 級別 數 必須 匹配 聯接 鍵 從 右 綜合 的 數目
right_index ︰ 相同 用法 作為 正確 綜合 left_index
how︰ 之一 '左', '右', '外在'、 '內部'。 默認 為 內部 。 每個 方法 的 更 詳細 說明 請 參閱 ︰
sort︰ 綜合 通過 聯接 鍵 按 字典 順序 對 結果 進行排序 。 默認值 為 True , 設置 為 False 將 提高 性能 極大地 在 許多 情況下
suffixes︰ 字符串 后綴 並 不適 用於 重疊 列 的 元組 。 默認值 為 ('_x', '_y')。
copy︰ 即使 重新索引 是 不 必要 總是 從 傳遞 的 綜合 對象 , 復制 的 數據 (默認值 True) 。 在 許多 情況下 不能 避免 , 但 可能會 提高 性能 / 內存 使用情況 。 可以 避免 復制 上述 案件 有些 病理 但 盡管如此 提供 此 選項 。
indicator︰ 將 列 添加 到 輸出 綜合 呼吁 _merge 與 信息 源 的 每 一行 。 _merge 是 絕對類型 , 並 對 觀測 其 合並 鍵 只 出現 在 '左' 的 綜合 , 觀測 其 合並 鍵 只 會出現 在 '正確' 的 綜合 , 和 兩個 如果 觀察 合並 關鍵 發現 在 兩個 right_only left_only 的 值 。
1.result = pd.merge(left, right, on='key')

2.result = pd.merge(left, right, on=['key1', 'key2'])
3.result = pd.merge(left, right, how='left', on=['key1', 'key2'])

4.result = pd.merge(left, right, how='right', on=['key1', 'key2'])

5.result = pd.merge(left, right, how='outer', on=['key1', 'key2'])

2、append
1.result = df1.append(df2)


2.result = df1.append(df4)
3.result = df1.append([df2, df3])
4.result = df1.append(df4, ignore_index=True)

4、join
left.join(right, on=key_or_keys) pd.merge(left, right, left_on=key_or_keys, right_index=True, how='left', sort=False)
1.result = left.join(right, on='key')


2.result = left.join(right, on=['key1', 'key2'])

3.result = left.join(right, on=['key1', 'key2'], how='inner')

4、concat
pd.concat(objs, axis=0, join='outer', join_axes=None, ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, copy=True)
objs︰ 一個 序列 或 系列 、 綜合 或 面板 對象 的 映射 。 如果 字典 中 傳遞 , 將 作為 鍵 參數 , 使用 排序 的 鍵 , 除非 它 傳遞 , 在 這 種情況下 的 值 將 會 選擇 (見 下文)。 任何 沒有任何 反對 將 默默地 被 丟棄 , 除非 他們 都 沒有 在 這 種情況下 將 引發 ValueError 。
axis: {0, 1, ...}, 默認值 為 0。 要 連接 沿 軸 。
join : {'內部'、 '外'}, 默認 '外'。 如何 處理 其他 axis(es) 上 的 索引 。 聯盟 內 、 外 的 交叉口 。
ignore_index ︰ 布爾值 、 默認 False 。 如果 為 True , 則 不要 串聯 軸 上 使用 的 索引 值 。 由此產生 的 軸 將 標記 0, ... , n - 1。 這 是 有用 的 如果 你 串聯 串聯 軸 沒有 有意義 的 索引 信息 的 對象 。 請注意 在 聯接 中 仍然 受到尊重 的 其他 軸 上 的 索引 值 。
join_axes ︰ 索引 對象 的 列表 。 具體 的 指標 , 用於 其他 n - 1 軸 而不是 執行 內部/外部 設置 邏輯 。
keys ︰ 序列 , 默認 為 無 。 構建 分層 索引 使用 通過 的 鍵 作為 最 外面 的 級別 。 如果 多個 級別 獲得通過 , 應 包含 元組 。
levels ︰ 列表 的 序列 , 默認 為 無 。 具體 水平 (唯一 值) 用於 構建 多重 。 否則 , 他們 將 推斷 鑰匙 。
names ︰ 列表中 , 默認 為 無 。 由此產生 的 分層 索引 中 的 級 的 名稱 。
verify_integrity ︰ 布爾值 、 默認 False 。 檢查 是否 新 的 串聯 的 軸 包含 重復項 。 這 可以 是 相對於 實際 數據 串聯 非常 昂貴 。
副本 ︰ 布爾值 、 默認 True 。 如果 為 False , 請 不要 , 不必要地 復制 數據 。
1.frames = [df1, df2, df3] 2.result = pd.concat(frames)


3.result = pd.concat(frames, keys=['x', 'y', 'z'])
4.result.ix['y']
A B C D
4 A4 B4 C4 D4 5 A5 B5 C5 D5 6 A6 B6 C6 D6 7 A7 B7 C7 D7
5.result = pd.concat([df1, df4], axis=1)
6.result = pd.concat([df1, df4], axis=1, join='inner')
7.result = pd.concat([df1, df4], axis=1, join_axes=[df1.index])
8.result = pd.concat([df1, df4], ignore_index=True)
