I have a folder that has 50 .csv files.
They are named UselessInfo.Needed_info.csv or UselessInfo.Needed.csv
I create a list of the names I want to assign as a variable to the representing df:
files = []
for filename in os.listdir():
if not filename.endswith('.ipynb'):
if '_' in filename or len(filename.split('.')) > 2:
files.append(filename.split('.')[1])
else:
files.append(filename.split('.')[0])
Then I iterate over the files and create a df for each file:
for filename in files:
filename = pd.read_csv(UselessInfo.{filename}.csv', delimiter=';')
But none of the names in files are created as a df, only filename holds the last file's data. Why the iteration of files does not create a df with the name in the files held by the filename variable?
I've seen this answer:
path = Path(os.getcwd())
dict_of_df = {}
for file in path.glob('*.csv'):
dict_of_df[file.stem] = pd.read_csv(file,delimiter=';')
Which creates a dict of df's but how can I achieve so that I create a variable for each file in the folder?