'Create a series of dataframes where each data frame is called the name of an iterable list
I have a feeling this is basic but its late so apologies upfront if its really simple
I have more but for simplicity lets say I have 2 .csv files. They are neflix.csv and amazon.csv (each file has a 'date' 'open' 'close' etc)
I could create a dataframe called the same name by opening them each one by one:
path = 'C:/Desktop/Python/Project/"netflix.csv"'
netflix = pd.read_csv(path)
path = 'C:/Desktop/Python/Project/"amazon.csv"'
amazon = pd.read_csv(path)
I'd like to rather iterate over a list of file names, read from the file and create a dataframe with the same name.
So I'm looking for something like this
path = 'C:/Desktop/Python/Project/'
file_list = ['netflix.csv','amazon.csv']
for i in file list:
file_list[i] = pd.read+csv(path + file_list[i])
That obviously doesnt work. The output in this case should be a dataframe called netflix with whats read from the netflix csv and a dataframe called amazon with the data read from the amazon csv. However its complicated further by the fact that the name cant be amazon.csv as there is a "." in it so it needs to be stored as amazon while the file_list[i] is obviously 'amazon.csv'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
