TypeError:不可散列的类型:使用熊猫从JSON文件读取时的“ dict”

时间:2020-08-31 00:08:13

标签: python json pandas

我正在尝试从JSON文件读取,但出现此错误:TypeError: unhashable type: 'dict'

import pandas as pd


osp_json_path = 'Data/syllabi.sample.json'

df_osp_data = pd.read_json(osp_json_path)


print(df.head())

以下是JSON文件的一些示例:

[
  {
    "id": 17308718202881,
    "syllabus_probability": 0.6546372771263123,
    "date": {
      "year": 2016,
      "term": null
    },
    "field": {
      "code": "11",
      "name": "Computer Science",
      "label_precision": 0.7397769689559937,
      "label_recall": 0.8223140239715576,
      "label_f1": 0.7788649797439575
    },
    "institution": {
      "id": 3994319585322,
      "grid_id": "grid.7112.5",
      "wikidata_id": "Q1783765",
      "unitid": null,
      "name": "Mendel University Brno",
      "url": "http:\/\/mendelu.cz\/en\/",
      "lat": 49.210208892822266
    },
    "extracted_metadata": {
      "code": {
        "text": "VT1",
        "clean_text": "VT1",
        "mean_p": 0.9811509251594543
      },
      "title": {
        "text": "Computer Technology I",
        "clean_text": "Computer Technology I",
        "mean_p": 0.9993407726287842
      },
      "date": {
        "text": "SS 2016\/2017",
        "clean_text": "SS 2016\/2017",
        "mean_p": 0.9996379613876343
      },
      "description": [
        {
          "text": "The aim of this course is to introduce students into the subject of computer science and data processing and to explain basic principles of computer operations. The part relating to operating systems is centered on operations with computer files and processes in systems Windows and Unix\/Linux.",
          "clean_text": "The aim of this course is to introduce students into the subject of computer science and data processing and to explain basic principles of computer operations. The part relating to operating systems is centered on operations with computer files and processes in systems Windows and Unix\/Linux.",
          "mean_p": 0.9988000392913818
        }
      ]
    },
    "text_md5": "18443cb0375d7ba646c5ac203aac7380",
    "mime_type": "text\/xml",
    "anonymized_text": "Department of Informatics (FBE) Time allowance:  full-time, period A\u00a02\/0, period B 2\/2  (hours of lectures per week \/ hours of seminars per week) Prerequisites for registration:  not  Computer Technology and Algorithms I  and not  Final Bachelor Exam Type of study:  consulting Form of teaching:  lecture, seminar Mode of completion and credits:  Fulfillment of requirements (2 credits) \u00a0 Course objective:  The aim of this course is to introduce students into the subject of computer science and data processing and to explain basic principles of computer operations. The part relating to operating systems is centered on operations with computer files and processes in systems Windows and Unix\/Linux. \u00a0 Course content:  1. Introduction to computer science  (allowance 2\/0) \u00a0 a. Basic concepts"
}

有办法避免这种TypeError吗?而且,并非所有字段都是必填字段,仅将使用“ id”和“ anonymized_text”,因此也可以过滤某些键。

0 个答案:

没有答案