【发布时间】:2020-06-28 06:56:24
【问题描述】:
你好 stackflowers,我是新手,我需要帮助
我最近在 python 中学习 pandas 库并尝试自动化输出文件,我成功了。但是当我想到将日期添加到输出路径时,我面临的错误是“只能将列表(而不是“str”)连接到列表中”
谁能帮我解决这个问题...
#saving in a path
timestamp = datetime.datetime.now()
t = timestamp.year, timestamp.month, timestamp.day
path = r'C:\Users\Revanth\Desktop\pandas_tutorials\New_Idle_Artist_List.xlsx'
split_filename = path.split(".")
exportpath = os.rename(path, split_filename[:-1]+'-'+join(t))
writer = pd.ExcelWriter(exportpath,engine='xlsxwriter',datetime_format='mmm d yyyy')
**Error displayed** : runfile('C:/Users/Revanth/.spyder-py3/Idle_artist_appliction.py', wdir='C:/Users/Revanth/.spyder-py3') Traceback (most recent call last):
File "C:\Users\Revanth\.spyder-py3\Idle_artist_appliction.py", line 71, in <module>
exportpath = os.rename(path, [split_filename[:-1]+'-'+join(t)])
TypeError: can only concatenate list (not "str") to list
【问题讨论】:
-
查看标准库中的
pathlib模块,以便在 Python 中正确处理路径和文件名
标签: python python-3.x pandas datetime