【问题标题】:Convert Dataframe.describe output to some json [duplicate]将 Dataframe.describe 输出转换为一些 json [重复]
【发布时间】:2020-02-04 23:56:44
【问题描述】:

我正在学习 Pandas + Python。

当我使用 var = dataFrame.describe() 时,我希望将输出转换为 json,以便我可以通过 Flask API 将其作为响应发送

    order_id  quantity
count  5.000000  5.000000
mean   1.200000  1.200000
std    0.447214  0.447214
min    1.000000  1.000000
25%    1.000000  1.000000
50%    1.000000  1.000000
75%    1.000000  1.000000
max    2.000000  2.000000

【问题讨论】:

  • describe返回一个数据框obj,可以直接使用var.to_json()

标签: python pandas flask


【解决方案1】:

使用DataFrame.to_json:

var.to_json()

输出:

'{"order_id":{"count":5.0,"mean":1.2,"std":0.447214,"min":1.0,"25%":1.0,"50%":1.0,"75%":1.0,"max":2.0},"quantity":{"count":5.0,"mean":1.2,"std":0.447214,"min":1.0,"25%":1.0,"50%":1.0,"75%":1.0,"max":2.0}}'

【讨论】:

    猜你喜欢
    • 2018-01-31
    • 1970-01-01
    • 1970-01-01
    • 2019-05-17
    • 2017-02-04
    • 1970-01-01
    • 1970-01-01
    • 2021-10-15
    • 2020-02-13
    相关资源
    最近更新 更多