The pandas.concat() method in Pandas

For the demonstration of concat function, we are using the datasource employees1.csv, and employees2.csv. You can download the datasource and use for the transformation.

The pandas.concat() function is used to concatenate (combine) pandas objects such as DataFrames or Series along a particular axis, either row-wise or column-wise. It provides flexibility in combining datasets while preserving the index and handling overlapping data.

Note: Here we are calling the function with the pandas’ library not with the dataframe/Series.

Example: Lets concat the two files.

Python

firstfile=pd.read_csv("employees1.csv")
secondfile=pd.read_csv("employees2.csv")
totalemp=pd.concat([firstfile, secondfile])
totalemp    

In the above code we are concatenating the two dataframes in a single dataframe. The output of the above code is shown below:

The pandas.concat() method in Pandas