python - pandas.DataFrame.to_json() 的 'orient' 参数的格式是什么?

标签 python pandas

查看the pandas Documentation on DataFrame's to_json method , orient 参数的解释含糊不清。它接受的参数类型是字符串,而不是字典。然而,它似乎实际上可以接受三件事,每件事都有自己的默认值:系列(默认“索引”)、DataFrame(默认“列”)和“JSON 字符串的格式”(无默认值)。

我想知道 orient 参数的可接受值是什么,以及它们对输出 json 的作用。

最佳答案

JSON 字符串的格式就是每个参数的输出如下所示

  • split : dict like {index -> [index], columns -> [columns], data -> [values]}
  • 记录:像 [{column -> value}, ..., {column -> value}] 这样的列表
  • index : dict like {index -> {column -> value}}
  • columns : dict like {column -> {index -> value}}
  • values : 只是值数组

关于python - pandas.DataFrame.to_json() 的 'orient' 参数的格式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28953012/

相关文章:

python - 如何使用 pandas 计算 CSV 文件中的两个数字

python - 在使用 pytest 运行测试之前执行健全性检查

python-2.7 - 获取 Pandas 数据框每一列中最后一个非 NaN 值的行索引

python - 比较元素并返回大于随机数的值作为 true

python - 如何比较 3 对 float 类型的 pandas dataframe 列?

python - Pandas:获取每行中最小值的列名称,并获取与其余列相比的%差异

python - 带字符串时间戳的平均聚合

python - 使用 Amazon Linux 的 Python 2.6.9 上的 mysql.connector 错误

python - Google App Engine : app. yaml 与 python 代码中的身份验证

python - 将列系列中的值替换为值为 1 的相应行