Skip to content
Advertisement

Python: Save variables-names and use them later in a loop

I downloaded DataFrames (depending on how many assets are in the variable “assets”) and created for each one its own variable by using globals().

Now, I require a loop to pick up each created variable, to perform other tasks with these variables.

Before this, I need to “save” the created variables, maybe in some kind of dictionary?

JavaScript

The created DataFrames are called:

JavaScript

Any help would be appreciated.

Advertisement

Answer

Creating variables by assigning to globals() is not only unnecessarily difficult in itself, it makes iterating over the result afterward also unnecessarily difficult. Avoid it altogether; instead of:

JavaScript

do:

JavaScript

Now if you want to do something with each of the dataframes you’ve created you can do:

JavaScript

If you need to do something with the symbol (FB, etc) do:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement