concat() (Pandas)
pd.concat() stacks DataFrames or Series together along an axis — vertically to add rows (axis=0) or horizontally to add columns (axis=1). Use it to glue pieces of data into one object.
Pandas
Unlike merge, concat doesn't match on keys; it simply lines objects up along one axis and aligns them by the other axis's labels. The most common use is stacking frames with the same columns on top of each other to build one long table.
By default concat preserves the original indexes, which can leave you with duplicate labels — pass ignore_index=True to renumber the result 0, 1, 2, …. With axis=1 it aligns on the index instead, padding non-matching rows with NaN. The keys argument can build a MultiIndex that records which piece each row came from.
For combining just two related tables on a key, prefer merge; reach for concat when you are appending homogeneous chunks.
Syntax
pd.concat(objs, axis=0, ignore_index=False, keys=None)Examples
Python
import pandas as pd
a = pd.DataFrame({"a": [1]})
b = pd.DataFrame({"a": [2]})
print(pd.concat([a, b], ignore_index=True))Output:
a
0 1
1 2