【问题标题】:JSON - Serialize pandas dataframe with numpy arrays entriesJSON - 使用 numpy 数组条目序列化 pandas 数据帧
【发布时间】:2017-12-06 20:16:27
【问题描述】:

我有一个pandas.DataFramenumpy.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


    【解决方案1】:

    你当然可以使用to_pickle()

    【讨论】:

    • 没错,但我更喜欢 json,因为它是我所知道的最易读的序列化。我现在更新了我的问题,专门针对 json。谢谢
    • 这根本不能回答问题。
    猜你喜欢
    • 2018-01-31
    • 2017-11-07
    • 2018-06-26
    • 2019-09-23
    • 2018-12-31
    • 1970-01-01
    • 2013-01-17
    • 1970-01-01
    • 2020-06-25
    相关资源
    最近更新 更多