【问题标题】:Why are the file names coming with an extra single quote at the beginning?为什么文件名开头带有额外的单引号?
【发布时间】:2021-04-09 00:42:06
【问题描述】:

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

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

此外,str(f) 包含我的输入文件名,并且每次都会更改。我得到的结果文件名是:

'Solvedsheet1
'Solvedsheet2
'Solvedsheet3

我只想:

Solvedsheet1
Solvedsheet2
Solvedsheet3

【问题讨论】:

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

标签: python pandas dataframe format filenames


【解决方案1】:

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

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

结果....

C:\Users\excel_outputs\Solvedsheet1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-29
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多