I have the following list:
I am trying to save an excel file named as each of the elements contained in the list. I’m not sure how to accomplish this. I tried:
for e in File_name_list: print (e) df.to_excel('C:/Users/user/Desktop/'%File_name_list)
So at the end I want to end up with five different files.
Thank you for your help.
When you do a for (a) in (b): loop, (b) describes the list you want to loop through, while (a) describes the element that each iteration of the loop is looking at. In your case, each iteration of the loop looks at either ‘A’ or ‘B’ or ‘C’, and stores that into your variable “e”. To use this variable, all you have to do is:
for e in File_name_list: print (e) df.to_excel('C:/Users/user/Desktop/'+e)
It’d also be a good idea to append the file type on the end of your file name like so:
you can use: