简体   繁体   中英

Python Pandas: Error when exporting DataFrame to CSV file

I am getting the following error when trying to export a pandas DataFrame to 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. 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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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