Reputation: 137
I want to assign distinct variable names to a list of 130 dataframes.
With fewer number of dataframes, I can do:
df1, df2, df3 = [list of dataframes]
However, with 130 of them, there must be a better way to achieve this.
I have tried:
[list of dataframe names] = [list of dataframes]
But, this does not work.
Ultimately, I want to create a list of dataframes each with distinct variable names, so that I should be able to access each dataframe by variable name.
Upvotes: 0
Views: 478
Reputation: 2328
It sounds like a dictionary is the solution you need and not a list. I'm using a dictionary comprehension below to build it similar to the way you would a list comprehension.
dataframes = {k:v for zip(list_of_dataframe_names, list_of_dataframes)}
And then whenever you want a certain dataframe just call it from the dictionary
needed_dataframe = dataframes[dataframe_name]
Upvotes: 1