Skip to content Skip to sidebar Skip to footer

Python Pandas To_csv Causes Oserror: [errno 22] Invalid Argument

My code is the following: import pandas as pd import numpy as np df = pd.read_csv('path/to/my/infile.csv') df = df.sort_values(['distance', 'time']) df.to_csv('path/to/my/outfile

Solution 1:

After exploring a lot of options, including the pandas library update to the latest version (1.2.4 as of today), changing the engine to "python" or "c", debugging, etc. I finally discovered what the issue was:

I had my CSV files stored in a folder that was constantly being synchronized in real-time with OneDrive.

YES! I discovered that the tray icon was becoming crazy and OneDrive was consuming resources at the same time I was doing algorithmic trading backtesting to my pet project. I paused sync and then it never failed again!!

I guess you can also exclude the folder from OneDrive or simply change the location where the CSVs are stored/written/accessed.

Solution 2:

I just had a similar issue and I was using back slash "\" which usually works in the past but this time turn out I had to use "/" instead which is extremely weird but it worked. Maybe you can try that?

Solution 3:

Apparently this problem is caused by a known bug reported here associated with a previous version of pandas. All I had to do was pip3 install --upgrade pandas and then restart the computer.

Solution 4:

In my case it worked once I specified the absolute, rather than the relative, path. I don't know why though--it hasn't happened before. Maybe because I'm working on an external hard drive?

Solution 5:

You should use "/" instead of using "" .

Post a Comment for "Python Pandas To_csv Causes Oserror: [errno 22] Invalid Argument"