首页 > 解决方案 > 使用for循环构建文件名并保存

问题描述

for i in range(1,151):
 Path = './Result/Normal_%d'%i
 Normal_i.to_csv(Path, sep=',' , header=None , index=None)

我想使用 for 循环来保存一个名为 Normal_1, Normal_2 ...Normal_150 的文件,我发现在 for 循环中使用“Normal_i”会出错。如何在 for 循环中保存名为 Normal_1、Normal_2 的文件?

标签: pythonfor-loop

解决方案


Path = './Result/Normal'
for i in range(1,151):
 Normal_i.to_csv(Path+str(i), sep=',' , header=None , index=None)

推荐阅读