Predictive Hacks

How to Append Multiple CSV files from a Folder in Pandas

Assume that you have multiple CSV files located in a specific folder, and you want to concatenate all of them in a Pandas Data Frame. We assume that our CSV files are under the “My_Folder“.

import os
import pandas as pd

# create an empty pandas data frame
df = pd.DataFrame()

# iterate over all files within "My_Folder"
for file in os.listdir("My_Folder"):
    if file.endswith(".csv"):
        df = pd.concat([df , pd.read_csv(os.path.join("My_Folder", file))], axis=0 )

# reset the index 
df.reset_index(drop=True, inplace=True)


Now the df consists of the CSV files within `My_Folder`.

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore


Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.


Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s