首页 > 解决方案 > pandas .to_csv 文件位置错误 OSError: [Errno 22] Invalid argument

问题描述

我之前编写了一个脚本,其中包含一个用于将数据帧转换为 .csv 并将其存储在本地的函数,它过去曾工作过,但现在我再次使用它,但它不会工作:

def write_to_csv(dataframe, filename):
    timestamp = datetime.utcnow().isoformat()
    dataframe.to_csv(fr'C:/Users/freddie.bazanye-lutu/BBDS_Repo/Scripts/{filename}-{timestamp}.csv', index=False, header=True) 

每次我运行它都会产生这个错误:

OSError: [Errno 22] Invalid argument: 'C:/Users/freddie.bazanye-lutu/BBDS_Repo/Scripts/Sandbox_glue_catalog-2021-10-08T10:56:27.991570.csv'

我已经尝试更改斜线的方向,我已经将熊猫更新到最新版本,我已经尝试更改我希望保存文件的位置,但都无济于事

标签: pythonpandasoserror

解决方案


推荐阅读