Skip to content

Instantly share code, notes, and snippets.

@luisfredgs
Last active September 19, 2024 18:13
Show Gist options
  • Save luisfredgs/a3bef4f65f166d3824eef182685004c1 to your computer and use it in GitHub Desktop.
Save luisfredgs/a3bef4f65f166d3824eef182685004c1 to your computer and use it in GitHub Desktop.
Convert pandas dataframe from CSV to JSON
import pandas as pd
data = pd.read_csv("file.csv", sep=",")
print(data.head(2))
with open('file.json', 'w') as f:
f.write(data.to_json(orient='records', lines=True))
# check
data = pd.read_json("file.json", lines=True)
print(data.head(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment