How to make a variable that changes name in a looping program (Python)

Viewed 31

I am trying to make a variable that changes based on the value of another variable (preferably a string, but i guess i could settle for a numerical variable if needed.)

For context, the program i am writing is taking a name, inputting it into an online form, taking data from the results, then looping to a new name.

Specifically, I want to set the name of a pandas dataframe to reflect the name of whatever person it is working on at that time.

I imagine that it would look something like this:

df4 = (f'df{name}')

(df1-3 are taken already) Except, nothing I try seems to work out, and always seems to just not function (without giving an error code).

The overall goal would be to have a "master dataframe"; and each time it loops combine the new dataframe

(that is called df{name}, which would come out something like dfjohn or dftom or dfmary} or whatever name it is working on);

With the "master dataframe" so that i can export all the data into one spreadsheet, (because i cannot find another efficient way to put it all in one spreadsheet without needing a changing variable anyways.)

Thank you in advance! Let me know if any more information is needed!

Edit: I guess i need to differentiate from another post. The other post that is linked does not answer my question. it suggests a way to not use them, but that does not work for my use case.

0 Answers
Related