Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么文件名在开头有一个额外的单引号?_Python_Pandas_Dataframe_Format_Filenames - Fatal编程技术网

Python 为什么文件名在开头有一个额外的单引号?

Python 为什么文件名在开头有一个额外的单引号?,python,pandas,dataframe,format,filenames,Python,Pandas,Dataframe,Format,Filenames,我试图在df.to_excel中动态命名我的输出文件,如下所示: df.to_excel(r'C:\Users\excel_outputs\'Solved'+str(f), index = False) 此外,str(f)包含我的输入文件名,并且每次都会更改。我得到的结果文件名是: 'Solvedsheet1 'Solvedsheet2 'Solvedsheet3 我只想: Solvedsheet1 Solvedsheet2 Solvedsheet3 这是一个字符串,所以 f = 'she

我试图在df.to_excel中动态命名我的输出文件,如下所示:

df.to_excel(r'C:\Users\excel_outputs\'Solved'+str(f), index = False)
此外,str(f)包含我的输入文件名,并且每次都会更改。我得到的结果文件名是:

'Solvedsheet1
'Solvedsheet2
'Solvedsheet3
我只想:

Solvedsheet1
Solvedsheet2
Solvedsheet3

这是一个字符串,所以

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

C:\Users\excel_outputs\Solvedsheet1
应该是df.to\u excel(r'C:\Users\excel\u outputs\Solved'+str(f),index=False)