Python Forum
dynamically create variables' names in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dynamically create variables' names in python
#1
Hi guys,
i want to create variables in the following way:

assign a name (e.g. var1), then add the name to the prefix of the variable:

name = 'var_1'
this_is_+name = pd.DataFrame()
the outcome i would like is having the variable renamed (on the fly) directly:

this_is_var_1 = pf.DataFrame()
the error i get is

Error:
File "<ipython-input-28-322e5421cff2>", line 4 df+name = pd.DataFrame() ^ SyntaxError: can't assign to operator
i tried many different way, including 'print' but it doesnt work and can't find any solution on the web.
Maybe i am formulating the question in the wrong way?
Thanks for your help.
Reply


Messages In This Thread
dynamically create variables' names in python - by marco_ita - Sep-17-2019, 05:12 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020