3

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 Answer 1

-1

You can of course use to_pickle()

Sign up to request clarification or add additional context in comments.

2 Comments

True, but I would really prefer json as it is the most readable serialization I know. I updated now my question to be specifically about json. Thanks
This doesn't answer the question at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.