How To Combine Multiple CSV Files With 8 Lines of Code PDF
How To Combine Multiple CSV Files With 8 Lines of Code PDF
Menu
Menu
But imagine if you have 100+ les to concatenate — are you willing to
do it manually? Doing this repetitively is tedious and error-prone.
If all the les have the same table structure (same headers & number
of columns), let this tiny Python script do the work.
import os
import glob
import pandas as pd
os.chdir("/mydir")
https://www.freecodecamp.org/news/how-to-combine-multiple-csv-files-with-8-lines-of-code-265183e0854/ 2/6
8/17/2019 How to combine multiple CSV files with 8 lines of code
Menu
extension = 'csv'
all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
And…it’s done!
Thank you for reading. Please give it a try, have fun and let me know
your feedback!
https://www.freecodecamp.org/news/how-to-combine-multiple-csv-files-with-8-lines-of-code-265183e0854/ 3/6
8/17/2019 How to combine multiple CSV files with 8 lines of code
Show comments
Python
A Python project in 30 lines of code: how to set up an SMS notification when your
favorite Twitcher is streaming
https://www.freecodecamp.org/news/how-to-combine-multiple-csv-files-with-8-lines-of-code-265183e0854/ 4/6
8/17/2019 How to combine multiple CSV files with 8 lines of code
Menu
#JAVASCRIPT
#WEB DEVELOPMENT
Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and
staff. You can make a tax-deductible donation here.
https://www.freecodecamp.org/news/how-to-combine-multiple-csv-files-with-8-lines-of-code-265183e0854/ 6/6