【发布时间】:2017-12-06 20:16:27
【问题描述】:
我有一个pandas.DataFrame 和numpy.ndarrays 条目(大小不同)。如何将其序列化为 json?
看来pandas目前不支持ndarrays的序列化:
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
密切相关的问题,其答案无法解决我的问题:
Storing Dataframe with Array Entries:我不能在那里使用好技巧,因为我的数据框由不同大小的数组组成。
Convert numpy type to python:如果有办法在DataFrame.to_json()中使用MyEncoder
【问题讨论】:
标签: python json pandas numpy serialization