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.

1 Answers

Matthew Barlowe On

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]