python - Exporting Pandas series as JSON - error with numpy types -


i want export rows pandas dataframe json. however, when exporting columns got error:

typeerror: false not json serializable 

or

typeerror: 0 not json serializable 

i looked in data , problem occurs numpy.int64 , numpy.bool_ (numpy.float64 works fine).

for example, problem appears following:

import pandas pd import simplejson json  df = pd.dataframe([[false,0],[true,1]], columns=['a','b']) json.dumps(df.ix[0].to_dict()) 

(the same thing happens dict(df.ix[0])).

is there simple workaround export pandas series json?

or @ least, function coerce numpy type closest type compatible json?

dataframe has method export json string:

>>> df.to_json() '{"a":{"0":false,"1":true},"b":{"0":0,"1":1}}' 

you can export directly file:

>>> df.to_json(filename) 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -