I would like to use a function's parameter to create dynamic names of dataframes and/or objects in Python. I have about 40 different names so it would be really elegant to do this in a function. Is there a way to do this or do I need to do this via 'dict'? I read that 'exec' is dangerous (not that I could get this to work). SAS has this feature for their macros which is where I am coming from. Here is an example of what I am trying to do (using '@' for illustrative purposes):
def TrainModels (mtype):
model_@mtype = ExtraTreesClassifier()
[email protected](X_@mtype, Y_@mtype)
TrainModels ('FirstModel')
TrainModels ('SecondModel')