Skip to content

Instantly share code, notes, and snippets.

@abelsonlive
Created December 12, 2013 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelsonlive/7931943 to your computer and use it in GitHub Desktop.
Save abelsonlive/7931943 to your computer and use it in GitHub Desktop.
convert a csv file into a json list of dicts
import pandas as pd
import json
import sys
def csv2json(file_path):
df = pd.read_csv(file_path, encoding='latin1')
output = []
for i in df.index:
row = {}
for k in df.keys():
row[k] = df[k][i]
output.append(row)
json.dumps(output)
if __name__ == '__main__':
csv2json(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment