I am creating pandas DataFrames in a for loop and I would like to save them in csv files with different names at each iteration of the for loop.
I know how to save one DataFrame:
path = r"C:\Users\SessionName\FolderName\FileName.csv"
df.to_csv(path)
Now when I have a list of strings, e.g.
countries = ['United States', 'China', 'Russia', 'India']
I would like the four files to be named United States_ranking.csv, China_ranking.csv, etc.
I have tried:
for country in countries:
path = r"C:\Users\SessionName\FolderName\" + country + "_ranking.csv"
But is won't work.