Created
December 2, 2013 11:30
-
-
Save BastinRobin/7748200 to your computer and use it in GitHub Desktop.
Pandas Dataframes 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 | |
import json | |
data = pd.read_csv('sample.csv') | |
d = [ | |
dict([ | |
(colname, row[i]) | |
for i,colname in enumerate(data.columns) | |
]) | |
for row in data.values | |
] | |
json.dump(d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple way to convert a pandas dataframe to json