
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to Merge multiple CSV Files into a single Pandas dataframe ?
To merge more than one CSV files into a single Pandas dataframe, use read_csv. At first, import the required Pandas library. Here. We have set pd as an alias −
import pandas as pd
Now, let’s say the following are our CSV Files −
Sales1.csv
Sales2.csv
We have set the path as string. Both the files are on the Desktop −
file1 = "C:\Users\amit_\Desktop\sales1.csv" file2 = "C:\Users\amit_\Desktop\sales2.csv"
Next, merge the above two CSV files. The pd.concat() merge the CSV files together −
dataFrame = pd.concat( map(pd.read_csv, [file1, file2]), ignore_index=True)
Example
Following is the code −
import pandas as pd file1 = "C:\Users\amit_\Desktop\sales1.csv" file2 = "C:\Users\amit_\Desktop\sales2.csv" print("Merging multiple CSV files...") # merge dataFrame = pd.concat( map(pd.read_csv, [file1, file2]), ignore_index=True) print(dataFrame)
Output
This will produce the following output −
Car Place UnitsSold 0 Audi Bangalore 80 1 Porsche Mumbai 110 2 RollsRoyce Pune 100 3 BMW Delhi 95 4 Mercedes Hyderabad 80 5 Lamborgini Chandigarh 80
- Related Articles
- How to Merge all CSV Files into a single dataframe – Python Pandas?
- Python Pandas- Create multiple CSV files from existing CSV file
- How to merge multiple files into a new file using Python?
- Creating a Dataframe using CSV files
- Writing a Pandas DataFrame to CSV file
- Python - How to write pandas dataframe to a CSV file
- How to Handle Large CSV files with Pandas?
- Python – Merge two Pandas DataFrame
- Merge Pandas DataFrame with a common column
- How to sort multiple columns of a Pandas DataFrame?
- Python Pandas - How to select multiple rows from a DataFrame
- How to convert a DataFrame into a dictionary in Pandas?
- How to load a TSV file into a Pandas Dataframe?
- Python - Merge Pandas DataFrame with Outer Join
- Python - Merge Pandas DataFrame with Inner Join

Advertisements