Last active
September 19, 2024 18:13
-
-
Save luisfredgs/a3bef4f65f166d3824eef182685004c1 to your computer and use it in GitHub Desktop.
Convert pandas dataframe from CSV to JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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