1 of 8

Intro to Pandas: Combining DFs

Lec 9

2 of 8

Objectives

  • Concat & Merge DFs

3 of 8

Concat DFs

4 of 8

Concat DFs

pd.concat([df1, df2], axis=0)

The concat() function performs concatenation operations of multiple tables along one of the axis (row-wise or column-wise).

  • axis=0 (or axis='rows') is horizontal axis.
  • axis=1 (or axis='columns') is vertical axis
  • By default, concatenation is along axis 0, so the resulting table combines the rows of the input tables.

5 of 8

Merge DFs

6 of 8

Merge DFs

pd.merge(df1, df2,

how =’____’, on=’col’)

  • df1: dataframe
  • df2: dataframe or series to merge with
  • how: type of merge - left (use keys from left frame), right, outer, inner
  • on: column or index level names to join on

7 of 8

Resource

8 of 8

Q/A break