Python pandas OSError: [Errno 22] Invalid argument

Today in this article, we will cover below aspects,

Issue Description

Python Pandas CSV to JSON or JSON to CSV conversion causes below error,

OSError: [Errno 22] Invalid argument

Below is the sample code to reproduce the error,

import pandas as pd
df = pd.read_csv (r'gs://test-bucket-13/Input/Adress.csv')
df.to_json (r'gs://test-bucket-13/output/temp/adress.json')

Resolution

There could be multiple other issue causing this incompatibility.

Recently I got this error in the GCP cloud while using Pandas library to converting the data CSV to JSON format.

This issue may also be caused while using a large size of the file for conversion using the panda’s library. For me, the issue occurred for the 20Kb file size as well. So I am assuming it’s important that other related packages are also compatible with the panda’s library version used.

I was able to resolve the issue simply by using below upgrade command,

pip3 install --upgrade pandas

If you get any issue even with the above fix, Please use few below steps to resolve the issue,

  • Please try to use the requirements.txt or setup.py file and specify the latest available pandas package.
  • Alternatively closing and opening the project could be helpful to reinstall any missing packages.

Did I miss anything else in these resolution steps?

Did the above steps resolve your issue? Please sound off your comments below!

Happy Coding !!



Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published(2024) best practices and guidelines for software design and development.



Leave a Reply

Your email address will not be published. Required fields are marked *