0

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.

user7288808
  • 117
  • 2
  • 8
  • @jezrael This is not the same question as "how to split a single dataframe into multiple dataframes". This is asking "how multiple dataframes can each be assigned to different variables". Please refer to me to a duplicate question if there exists one. – user7288808 May 07 '19 at 17:41
  • @jezrael Could you please remove "duplicate"? Or please refer me to the correct answer. Thank you! – user7288808 May 09 '19 at 21:17

1 Answers1

1

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]
Matthew Barlowe
  • 2,229
  • 1
  • 14
  • 24