Created
December 12, 2013 17:31
-
-
Save abelsonlive/7931943 to your computer and use it in GitHub Desktop.
convert a csv file into a json list of dicts
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 | |
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