git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

ValueError: arrays must all be same length


Hello,

I got a json response from an API and tried to use pandas to put data into
a dataframe.

However, I kept getting this ValueError: arrays must all be same length.

Can anyone help?

The following is the json text.  Regards, Shao

{
  "locationId": "1-1004508435",
  "providerId": "1-101641521",
  "organisationType": "Location",
  "type": "Social Care Org",
  "name": "Meadow Rose Nursing Home",
  "brandId": "BD510",
  "brandName": "BRAND MACC Care",
  "onspdCcgCode": "E38000220",
  "onspdCcgName": "NHS Birmingham and Solihull CCG",
  "odsCode": "VM4G9",
  "uprn": "100070537642",
  "registrationStatus": "Registered",
  "registrationDate": "2013-12-16",
  "dormancy": "N",
  "numberOfBeds": 56,
  "postalAddressLine1": "96 The Roundabout",
  "postalAddressTownCity": "Birmingham",
  "postalAddressCounty": "West Midlands",
  "region": "West Midlands",
  "postalCode": "B31 2TX",
  "onspdLatitude": 52.399843,
  "onspdLongitude": -1.989241,
  "careHome": "Y",
  "inspectionDirectorate": "Adult social care",
  "mainPhoneNumber": "01214769808",
  "constituency": "Birmingham, Northfield",
  "localAuthority": "Birmingham",
  "lastInspection": {
    "date": "2020-06-24"
  },
  "lastReport": {
    "publicationDate": "2020-10-01"
  },
  "relationships": [

  ],
  "locationTypes": [

  ],
  "regulatedActivities": [
    {
      "name": "Accommodation for persons who require nursing or personal care",
      "code": "RA2",
      "contacts": [
        {
          "personTitle": "Mr",
          "personGivenName": "Steven",
          "personFamilyName": "Kazembe",
          "personRoles": [
            "Registered Manager"
          ]
        }
      ]
    },
    {
      "name": "Treatment of disease, disorder or injury",
      "code": "RA5",
      "contacts": [
        {
          "personTitle": "Mr",
          "personGivenName": "Steven",
          "personFamilyName": "Kazembe",
          "personRoles": [
            "Registered Manager"
          ]
        }
      ]
    }
  ],
  "gacServiceTypes": [
    {
      "name": "Nursing homes",
      "description": "Care home service with nursing"
    }
  ],
  "inspectionCategories": [
    {
      "code": "S1",
      "primary": "true",
      "name": "Residential social care"
    }
  ],
  "specialisms": [
    {
      "name": "Caring for adults over 65 yrs"
    },
    {
      "name": "Caring for adults under 65 yrs"
    },
    {
      "name": "Dementia"
    },
    {
      "name": "Physical disabilities"
    }
  ],
  "inspectionAreas": [

  ],
  "currentRatings": {
    "overall": {
      "rating": "Requires improvement",
      "reportDate": "2020-10-01",
      "reportLinkId": "1157c975-c2f1-423e-a2b4-66901779e014",
      "useOfResources": {

      },
      "keyQuestionRatings": [
        {
          "name": "Safe",
          "rating": "Requires improvement",
          "reportDate": "2020-10-01",
          "reportLinkId": "1157c975-c2f1-423e-a2b4-66901779e014"
        },
        {
          "name": "Well-led",
          "rating": "Requires improvement",
          "reportDate": "2020-10-01",
          "reportLinkId": "1157c975-c2f1-423e-a2b4-66901779e014"
        },
        {
          "name": "Caring",
          "rating": "Good",
          "reportDate": "2019-10-04",
          "reportLinkId": "63ff05ec-4d31-406e-83de-49a271cfdc43"
        },
        {
          "name": "Responsive",
          "rating": "Good",
          "reportDate": "2019-10-04",
          "reportLinkId": "63ff05ec-4d31-406e-83de-49a271cfdc43"
        },
        {
          "name": "Effective",
          "rating": "Requires improvement",
          "reportDate": "2019-10-04",
          "reportLinkId": "63ff05ec-4d31-406e-83de-49a271cfdc43"
        }
      ]
    },
    "reportDate": "2020-10-01"
  },
  "historicRatings": [
    {
      "reportLinkId": "63ff05ec-4d31-406e-83de-49a271cfdc43",
      "reportDate": "2019-10-04",
      "overall": {
        "rating": "Requires improvement",
        "keyQuestionRatings": [
          {
            "name": "Safe",
            "rating": "Requires improvement"
          },
          {
            "name": "Well-led",
            "rating": "Requires improvement"
          }
        ]
      }
    },
    {
      "reportLinkId": "4f20da40-89a4-4c45-a7f9-bfd52b48f286",
      "reportDate": "2017-09-08",
      "overall": {
        "rating": "Good",
        "keyQuestionRatings": [
          {
            "name": "Safe",
            "rating": "Good"
          },
          {
            "name": "Well-led",
            "rating": "Good"
          },
          {
            "name": "Caring",
            "rating": "Good"
          },
          {
            "name": "Responsive",
            "rating": "Good"
          },
          {
            "name": "Effective",
            "rating": "Requires improvement"
          }
        ]
      }
    },
    {
      "reportLinkId": "0cc4226b-401e-4f0f-ba35-062cbadffa8f",
      "reportDate": "2016-06-11",
      "overall": {
        "rating": "Requires improvement",
        "keyQuestionRatings": [
          {
            "name": "Safe",
            "rating": "Requires improvement"
          },
          {
            "name": "Well-led",
            "rating": "Requires improvement"
          },
          {
            "name": "Caring",
            "rating": "Requires improvement"
          },
          {
            "name": "Responsive",
            "rating": "Requires improvement"
          },
          {
            "name": "Effective",
            "rating": "Good"
          }
        ]
      }
    },
    {
      "reportLinkId": "a11c1e52-ddfd-4cd8-8b56-1b96ac287c96",
      "reportDate": "2015-01-12",
      "overall": {
        "rating": "Good",
        "keyQuestionRatings": [
          {
            "name": "Safe",
            "rating": "Good"
          },
          {
            "name": "Well-led",
            "rating": "Good"
          },
          {
            "name": "Caring",
            "rating": "Good"
          },
          {
            "name": "Responsive",
            "rating": "Requires improvement"
          },
          {
            "name": "Effective",
            "rating": "Good"
          }
        ]
      }
    }
  ],
  "reports": [
    {
      "linkId": "1157c975-c2f1-423e-a2b4-66901779e014",
      "reportDate": "2020-10-01",
      "reportUri": "/reports/1157c975-c2f1-423e-a2b4-66901779e014",
      "firstVisitDate": "2020-06-23",
      "reportType": "Location"
    },
    {
      "linkId": "63ff05ec-4d31-406e-83de-49a271cfdc43",
      "reportDate": "2019-10-04",
      "reportUri": "/reports/63ff05ec-4d31-406e-83de-49a271cfdc43",
      "firstVisitDate": "2019-08-28",
      "reportType": "Location"
    },
    {
      "linkId": "4f20da40-89a4-4c45-a7f9-bfd52b48f286",
      "reportDate": "2017-09-08",
      "reportUri": "/reports/4f20da40-89a4-4c45-a7f9-bfd52b48f286",
      "firstVisitDate": "2017-07-19",
      "reportType": "Location"
    },
    {
      "linkId": "0cc4226b-401e-4f0f-ba35-062cbadffa8f",
      "reportDate": "2016-06-11",
      "reportUri": "/reports/0cc4226b-401e-4f0f-ba35-062cbadffa8f",
      "firstVisitDate": "2016-03-15",
      "reportType": "Location"
    },
    {
      "linkId": "a11c1e52-ddfd-4cd8-8b56-1b96ac287c96",
      "reportDate": "2015-01-12",
      "reportUri": "/reports/a11c1e52-ddfd-4cd8-8b56-1b96ac287c96",
      "firstVisitDate": "2014-08-12",
      "reportType": "Location"
    }
  ]
}

In [ ]:


In [25]:
j


import pandas as pd

import json

j = json.JSONDecoder().decode(req.text)  ###req.json

df = pd.DataFrame.from_dict(j)