I have a list of filenames and filepaths that I have stored in a python dictionary. I am trying to read the files using pandas' read_csv and assign the dataframe names from the dictionary. I can read and print the dataframes while running the for loop but I cannot call the dataframes after the loop is finished. I could append all the dataframes in a list but that way I am not able to assign these dataframes different names which are also stored in the dictionary.
I checked various forums but none of them explain why the for loop with pd.read_csv doesn't work and why I am not able to assign the names to the dataframes in the for loop to later use them.
import pandas as pd
files_dict = {"Filter":"OUTTYPENM.csv","previous":"previous.csv"}
for key, value in files_dict.items():
key = pd.read_csv(value)
Filter.head()
I expect to see the first five lines from the Filter dataframe as if I have read the dataframe as following.
Filter = pd.read_csv("OUTTYPENM.csv")
All the csv files are in the current working directory.
When I run the for loop code, and run the Filter.head(), I get an error saying - NameError: name 'Filter' is not defined
print(key)?Filter