JSON - Serialize pandas dataframe with numpy arrays entries

Viewed 955

I have a pandas.DataFrame with numpy.ndarrays entries (of different sizes). How can I serialize it to json?

It seems that pandas doesn't support serialization of ndarrays at the moment:

pandas.DataFrame([{'a': numpy.array(1)}, {'a': numpy.array((1,2))}]).to_json()
TypeError: array(1) (0d array) is not JSON serializable at the moment

Closely related questions whose answers won't solve my problem:

Storing Dataframe with Array Entries: I can't use the nice trick there because my dataframe consists of arrays with varying sizes.

Convert numpy type to python: If there was a way to use MyEncoder in DataFrame.to_json()

1 Answers
Related