首页 > 解决方案 > Why are the file names coming with an extra single quote at the beginning?

问题描述

I am trying to dynamically name my output files in df.to_excel as shown below:

df.to_excel(r'C:\Users\excel_outputs\'Solved'+str(f), index = False)

Also, str(f) contains my input file name and changes every time. The resulting filenames I'm getting are:

'Solvedsheet1
'Solvedsheet2
'Solvedsheet3

I just want:

Solvedsheet1
Solvedsheet2
Solvedsheet3

标签: pythonpandasdataframeformatfilenames

解决方案


这是一个单一的字符串,所以....

f = 'sheet1'
x = r"C:\Users\excel_outputs\Solved"+str(f)
print(x)

结果....

C:\Users\excel_outputs\Solvedsheet1

推荐阅读