Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

For row-wise concatenation, pass ignore_index=True to pd.concat:

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

This replaces the combined DataFrame’s row labels with a fresh sequence starting at 0. The columns and their values remain; only the labels on the concatenation axis are replaced.

Reset the row index while concatenating DataFrames

Here is a complete example with nonconsecutive source indexes:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import pandas as pd

df1 = pd.DataFrame({"name": ["Ada", "Grace"]}, index=[10, 11])
df2 = pd.DataFrame({"name": ["Linus"]}, index=[42])

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

Because the default concatenation axis is rows (axis=0), the resulting index is RangeIndex(start=0, stop=3, step=1) in this example, and the name values are retained. The pandas 3.0.5 API reference defines ignore_index=True as not using index values along the concatenation axis and labeling the resulting axis from 0 through n − 1: pandas.concat API reference.

What ignore_index changes—and what it leaves alone

The option affects only the axis along which pandas concatenates:

  • Row-wise (axis=0, the default): row index labels are replaced. Columns are still aligned by column name.
  • Column-wise (axis=1): output column labels are replaced; the row indexes remain relevant for aligning rows.

For row-wise concatenation, join determines which columns appear. Its default, join='outer', takes the union of the input columns; join='inner' keeps only their intersection. ignore_index=True does not change this behavior. See the pandas guide to merging, joining, and concatenation.

Use it with Series, too

The same option works when concatenating Series:

result = pd.concat([s1, s2], ignore_index=True)

The pandas API reference demonstrates concatenating two two-element Series this way, producing index labels 0, 1, 2, and 3: pandas.concat API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose whether to preserve labels or identify each input

Reset the concatenated index when source labels are incidental—for example, when combining rows from separate DataFrames into one result. If the original labels carry meaning, omit ignore_index=True so pandas preserves them.

If you need to record which input contributed each row, use keys to add an outer level to the resulting index rather than discarding row labels. The pandas 3.0.0 release notes specify that ignore_index=True with non-None keys raises ValueError; these options cannot be combined in that release: pandas 3.0.0 release notes.

Collect objects before concatenating

Avoid calling pd.concat once per row inside a loop. Collect the DataFrames or Series first, then concatenate once:

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

The pandas API reference recommends collecting objects and making one concatenation call; the user guide notes that repeated concatenation can create unnecessary copies. See the API reference and user guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use current concat syntax

For current pandas code, use pd.concat rather than older examples based on DataFrame.append. The pandas 1.5.3 reference marked DataFrame.append deprecated since pandas 1.4.0 and recommended concat: pandas 1.5.3 DataFrame.append reference. The current pandas 3.0 API also documents the copy keyword as ignored and for removal in pandas 4.0, so omit it in new calls to pd.concat: pandas.concat API reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When concat is not the right operation

ignore_index=True does not make concatenation match records using key columns. When the task is relational matching—such as combining rows based on a shared identifier—use pandas merge or join instead. The pandas merging guide distinguishes those operations from concatenation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.