I have the following code for creating a dictionary of data frames using csv files:
l = ['employees','positions']
d = {}
for x in l:
d[x] = pd.read_csv("P:\\python_work\\data_sets\\" + x + ".csv")
How would I do the same using a list of data frames that already exist in memory?
This doesn't work but maybe it helps clarify what I'm trying to do:
l = ['df1','df2']
d = {}
for x in l:
d[x] = x
I would then be able to access individual data frames like so:
d['df1']
I provided the example using csv files because it works and it has the same end result (a dictionary of data frames).
Here's an example of the desired contents of the dictionary:
{'employees': id name date
0 1 bob 1/1/2018
1 2 sally 1/2/2018, 'positions': pos desc status
0 12454 director a
1 65444 manager i}
I want to use a list of existing data frames rather than csv files. I tried using a list without quotes but I get an error:
l = [employees, positions]
d = {}
for x in l:
d[x] = x
...but I get this error:
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed