I have a folder with a lot of files. I want to create a loop or function where I can read all the files and create corresponding data frames for each one of the files with the prefix format 'filename'+_df
.
I have this code that reads everything and creates a large data frame from all the files in the folder, but I'm not sure how to modify it to create multiple data frames and use the filename as a prefix:
import os
import pandas as pd
path = os.path.join(os.getcwd(),'folder')
files = [os.path.join(path,i) for i in os.listdir(path) if os.path.isfile(os.path.join(path,i))]
df = pd.DataFrame()
for file in files:
_df = pd.read_csv(file)
df = df.append(_df)
If there's a better way to do this, that would be great as well.