Skip to content

Instantly share code, notes, and snippets.

@BastinRobin
Created December 2, 2013 11:30
Show Gist options
  • Save BastinRobin/7748200 to your computer and use it in GitHub Desktop.
Save BastinRobin/7748200 to your computer and use it in GitHub Desktop.
Pandas Dataframes to JSON
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)
@BastinRobin
Copy link
Author

Simple way to convert a pandas dataframe to json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment