简体   繁体   English

Python Pandas:将 DataFrame 导出到 CSV 文件时出错

[英]Python Pandas: Error when exporting DataFrame to CSV file

I am getting the following error when trying to export a pandas DataFrame to csv.尝试将 pandas DataFrame 导出到 csv 时出现以下错误。

    Traceback (most recent call last):
    File "C:/Users/riley/PycharmProjects/EarlyPaidLoanReport/EarlyPaidOff.py", line 91, in <module>
    LastTransactionDate.to_csv(LastTransactionDate, 'example.csv')
    File "C:\Users\riley\Anaconda3\lib\site-packages\pandas\core\frame.py", line 1344, in to_csv
    formatter.save()
    File "C:\Users\riley\Anaconda3\lib\site-packages\pandas\formats\format.py", line 1526, in save
    compression=self.compression)
    File "C:\Users\riley\Anaconda3\lib\site-packages\pandas\io\common.py", line 424, in _get_handle
    f = open(path, mode, errors='replace')
    TypeError: invalid file:        AutoNumber                       LoanAgreementID  \

I'm not sure why I am getting this error.我不确定为什么会收到此错误。 I've been writing to csv using pandas many times in the past.我过去曾多次使用 pandas 写信给 csv。 Could someone please help to fix this error?有人可以帮忙解决这个错误吗?

LastTransactionDate.to_csv(LastTransactionDate, 'example.csv')

Your syntax is wrong.你的语法是错误的。 Unless I am missing something, just do this:除非我遗漏了什么,否则请执行以下操作:

LastTransactionDate.to_csv('example.csv')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM