Python-将JSON读取的文件转换为可用的DataFrame

问题描述 投票:0回答:1

我是Python的新手,正在尝试使用以下代码读取JSON文件并将其转换为带有列标题的数据框等。我只是似乎无法理解我在这里做错了,因为输出如下所示在下面

import pandas as pd
import matplotlib as plt

other_path = "c:\\users\\xyz\\documents\\covid.json"
df = pd.read_json(other_path)
print (df.head())
print (type (df))

输出

enter image description here

python json dataframe
1个回答
0
投票

使用参数orient="records"参见文档here

df = pd.read_json(other_path, orient="records")
© www.soinside.com 2019 - 2024. All rights reserved.