Concatenate large csv files using python

import shutil
csv_files = ['source1.csv', 'source2.csv', 'source3.csv', 'source4.csv', 'source5.csv']
target_file_name = 'dest.csv';
shutil.copy(csv_files[0], target_file_name)
with open(target_file_name, 'a') as out_file:
for source_file in csv_files[1:]:
with open(source_file, 'r') as in_file:
# if your csv doesn't contains header, then remove the following line.
in_file.readline()
shutil.copyfileobj(in_file, out_file)
in_file.close()
out_file.close()

--

--

--

Providing simple solutions for complex problems.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

AWS Case Study : Unilever

HTTPS requet from ESP8266

kaveri 🥺❤️ finally our blogs are here!!🌸 Bloom!!

How I Became a Code Beginner with Literature Background

Euphoria’s Roadmap

Get Rates for Platinum in Argentine Peso With an API

Automated API testing with Postman

Who’s really running your industrial IoT project?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prince Francis

Prince Francis

Providing simple solutions for complex problems.

More from Medium

Create Word File with Python

Generator in Python

Flying Tello EDU Drones in Python

Python Functions and Packages: