Skip to main content
Albero Academy

Concatenating

Stack DataFrames vertically or glue them side by side.

Aggregation & Combining7 min

Where merge joins on a key, concat simply stacks DataFrames — vertically (more rows) or horizontally (more columns). It's how you combine monthly files or append new records.

Stacking rows

append records
pd.concat([df_jan, df_feb, df_mar], ignore_index=True)
# ignore_index=True renumbers the index 0..n instead of repeating labels

Side by side

axis=1
pd.concat([df_features, df_labels], axis=1) # glue columns together

Key takeaways

  1. 01concat stacks DataFrames: axis=0 (default) adds rows, axis=1 adds columns.
  2. 02Use ignore_index=True when stacking rows to get a clean 0..n index.
  3. 03concat combines same-shaped tables; merge joins related tables on a key.
  4. 04It is the tool for combining per-period files or appending records.

Finished this chapter?

Mark it complete to track your progress through Pandas.