我有一些参数
p=221
q=4.22
r=3.3
我想将我的输出值保存在名为p_221__q_4.22__r_3.3.csv的文件中,我尝试过这样做
file_name = open('p_{}__q_{}__r_{}.csv'.format(p,q,r),'w')
output.to_csv(filename+'.csv', index=False)
但错误出现为“替换索引2超出位置参数元组的范围”
发布于 2020-12-08 01:55:24
如果您的output
变量是pandas数据帧,只需使用to_csv()
函数:
p=221
q=4.22
r=3.3
output = pd.DataFrame([p,q,r])
file_name = 'p_{}__q_{}__r_{}.csv'.format(p,q,r)
output.to_csv(file_name)
通过使用to_csv()函数,无需使用open()打开任何文件
https://stackoverflow.com/questions/65186605
复制相似问题