In this article, we will see how to read multiple CSV files into separate DataFrames. For reading only one data frame we can use pd.read_csv() function of pandas. It takes a path as input and returns data frame like
df = pd.read_csv("file path")
Let’s have a look at how it works
Here, crime.csv is the file in the current folder. CSV is the folder that contains the crime.csv file and CSV Reader.ipynb is the file containing the above code.
It is the data frame that is read from the above function. One more file is present in the folder named – username.csv. To read them both and store them in different data frames use the below code
dataframes_list contains all the data frames separately.
Here is another approach, now suppose that there are many files, and we don’t know the names and number then, use the below code
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course