【发布时间】:2021-01-14 00:08:30
【问题描述】:
我想读取从dict() 生成的 JSON 文件,然后我可以制作饼图。到目前为止我的代码:
import json
import pandas as pd
openJson = open("path")
jsonFile = json.load(openJson)
df = pd.DataFrame.from_dict(jsonFile)
我遇到的问题是我什至无法尝试绘制图表,因为我无法将 JSON 转换为数据框。我得到的错误是ValueError: If using all scalar values, you must pass an index。我也尝试过写df = pd.DataFrame.from_dict(jsonFile, index=[0]),如在类似帖子中找到的那样,但似乎index 是一个意外的论点。
如何读取该 JSON 以便对其进行绘图?
LE:添加了名为 category.json 的 JSON 文件
{"Restaurants": 678.7800000000001, "Utilities": 807.26, "Services": 35.67, "Transport": 1295.65, "Shopping": 1454.15, "Groceries": 1162.89}
【问题讨论】:
-
Json 长什么样子
-
@ifly6 我已经编辑了我的帖子以添加文件
标签: python pandas matplotlib