Python机器学习(八十三)Pandas 读取 JSON 数据

要从Json文件中读取数据,可以使用Pandas的read_json方法。

Json文件的内容:

{
  "apples": {
      "June": 3,
      "Robert": 2,
      "Lily": 0,
      "David": 1
  },
  "oranges": {
      "June": 0,
      "Robert": 3,
      "Lily": 7,
      "David": 2
  }
}

使用Pandas加载Json文件

df = pd.read_json('purchases.json')

df

输出

        apples  oranges
David        1        2
June         3        0
Lily         0        7
Robert       2        3

猜你喜欢

转载自www.cnblogs.com/huanghanyu/p/13174008.html