This question has been edited to include the answer.
Simple question. I would like to append a variable with the string from another variable. For example:
countries = ['USA','CAN','MEX']
df_imp_USA = read_csv(r'%s_final_forecasts.csv' % countries[0]);
What syntax would allow me to automatically change df_imp_USA
according to the contents in countries
? I need to do this because I want to put this line into a for loop. Thanks.
Answer
As the comments suggest, using dictionaries is preferable to creating new variables. I saw this in previous answers but couldn't figure out how to use dictionaries in my code. I include the syntax below in case it may help others.
df_imp = {} # define the dic
for country in countries:
df_imp[country] = read_csv(r'%s_final_forecasts.csv' % country)
Now you can access the dict like this:
df_imp['USA']