Reputation: 89
for i in range(1,151):
Path = './Result/Normal_%d'%i
Normal_i.to_csv(Path, sep=',' , header=None , index=None)
I would like to use for loop to save a file that is name Normal_1, Normal_2 ...Normal_150 and I found out that using "Normal_i" in for loop makes an error. What Can I do to save a file that is named Normal_1, Normal_2 in for loop?
Upvotes: 1
Views: 1114
Reputation: 900
A good answer has already been given, but here is a fun python thing you could try:
eval(f"Normal_i.to_csv({Path}File{i}, sep=',' , header=None , index=None)")
About eval().
PS: I do not endorse doing this.
Upvotes: 0
Reputation: 466
Path = './Result/Normal'
for i in range(1,151):
Normal_i.to_csv(Path+str(i), sep=',' , header=None , index=None)
Upvotes: 1