0
0
Pandasdata~5 mins

append equivalent with concat in Pandas

Choose your learning style9 modes available
Introduction

We use concat to join two or more tables (DataFrames) together. It helps combine data easily.

You want to add rows from one table to another.
You have multiple data files and want to combine them into one table.
You want to join data vertically or horizontally.
You want a faster or more flexible way than <code>append</code> to combine tables.
Syntax
Pandas
pd.concat([df1, df2], axis=0, ignore_index=False)

df1 and df2 are the tables (DataFrames) you want to join.

axis=0 means join rows (one below the other). Use axis=1 to join columns side by side.

Examples
Joins two DataFrames by rows (default axis=0).
Pandas
pd.concat([df1, df2])
Joins two DataFrames by columns (side by side).
Pandas
pd.concat([df1, df2], axis=1)
Joins rows and resets the row numbers to be continuous.
Pandas
pd.concat([df1, df2], ignore_index=True)
Sample Program

This code creates two tables with names and ages. Then it joins them using concat to get one bigger table with all rows.

Pandas
import pandas as pd

# Create two small DataFrames with same columns
df1 = pd.DataFrame({'Name': ['Alice', 'Bob'], 'Age': [25, 30]})
df2 = pd.DataFrame({'Name': ['Charlie', 'David'], 'Age': [35, 40]})

# Use concat to join them like append
combined = pd.concat([df1, df2], ignore_index=True)

print(combined)
OutputSuccess
Important Notes

concat is more powerful and flexible than append.

Use ignore_index=True to reset row numbers after joining.

Remember to pass a list of DataFrames inside concat.

Summary

concat joins tables by rows or columns.

It replaces append for adding rows.

Use ignore_index=True to reset row numbers.