串接

給試算表使用者的 pandas 合併實務

John Miller

Principal Data Scientist

串接基礎

$$

  • 類似試算表的 CONCATENATE
  • 模擬複製貼上儲存格
  • pd.concat() 可沿列或欄串接

木頭拼接

給試算表使用者的 pandas 合併實務

串接列

$$

  • 處理分割資料時很實用

$$

pd.concat([df1, df2, ...])
  • 以唯一鍵作為資料框索引
  • 預設包含所有列

以命名索引串接列

給試算表使用者的 pandas 合併實務

索引重疊時串接列

$$

  • 資料框索引可能重疊

  • 別擔心!

pd.concat([df1, df2, ...],
    ignore_index=True)

以一般索引串接列

給試算表使用者的 pandas 合併實務

串接欄

$$

  • 就像把表格並排貼上
  • 橫向(欄):axis=1
pd.concat([df1, df2, ...], 
    axis=1)
  • 預設包含所有欄

串接欄

給試算表使用者的 pandas 合併實務

一起來練習吧!

給試算表使用者的 pandas 合併實務

Preparing Video For Download...