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()

nivniv
  • 3,421
  • 5
  • 33
  • 40

1 Answers1

-1

You can of course use to_pickle()

Binyamin Even
  • 3,318
  • 1
  • 18
  • 45