concat()
noun
say it: “kun-KAT” /kənˈkæt/
A pandas function that stacks tables with the same columns into one, putting the rows of each under the last.
What does concat() do in pandas?
concat(), written pd.concat, stacks tables that share their columns, putting the rows of one under the other and
matching the columns by name. ignore_index=True numbers the stacked rows from 0 again.
import pandas as pd
fall = pd.DataFrame({"student_id": [101, 102], "score": [88, 92]})
spring = pd.DataFrame({"student_id": [101, 102], "score": [90, 85]})
both = pd.concat([fall, spring], ignore_index=True)
print(len(both)) # 4
In a sentence
- “The report script used concat() to stack every week's file into one table.”
- “concat() put the spring scores under the fall scores.”
Level: Journeyman · More Python terms at this level
Updated