Revisions
-
ameliagreenhall revised this gist
Feb 4, 2013 . 1 changed file with 20 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,29 @@ """ tiny script to convert a pandas data frame into a JSON object orig: https://gist.github.com/1486027 via Mike Dewar Test data: df = pandas.DataFrame({ "time" : [1,2,3,4,5], "temp" : np.random.rand(5) }) """ import json as json def to_json(df,filename): d = [ dict([ (colname, row[i]) for i,colname in enumerate(df.columns) ]) for row in df.values ] return json.dump(d, open(filename + '.json', 'w')) to_json(df, 'my_filename') # Preview file: !head my_filename.json -
mikedewar revised this gist
Jan 18, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ tiny script to convert a pandas data frame into a JSON object """ import ujson as json import pandas import numpy as np -
mikedewar created this gist
Dec 16, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ """ tiny script to convert a pandas data frame into a JSON object """ import json import pandas import numpy as np df = pandas.DataFrame({ "time" : [1,2,3,4,5], "temp" : np.random.rand(5) }) d = [ dict([ (colname, row[i]) for i,colname in enumerate(df.columns) ]) for row in df.values ] return json.dumps(d)