0

Data sample:

import pandas as pd

patients_df = pd.read_json('C:/MyWorks/Python/Anal/data_sample.json', orient="records", lines=True)

patients_df.head()

//in python



//my json data sample

  "data1": {
    "id": "myid",
    "seatbid": [
      {
        "bid": [
          {
            "id": "myid",
            "impid": "1",
            "price": 0.46328014,
            "adm": "adminfo",
            "adomain": [
              "domain.com"
            ],
            "iurl": "url.com",
            "cid": "111",
            "crid": "1111",
            "cat": [
              "CAT-0101"
            ],
            "w": 00,
            "h": 00
          }
        ],
        "seat": "27"
      }
    ],
    "cur": "USD"
  },

What I want to do is to check if there is a "cat" value in my very large JSON data. The "cat" value may/may not exist, but I'm trying to use Python Pandas to check it.

for seatbid in patients_df["win_res"]:

    for bid in seatbid["seatbid"]:

I tried to access JSON data while writing a loop like that, but it's not being accessed properly. I simply want to check if "cat" exist or not.

1 Answer 1

2

You can use python's json library as follows:

import json
patient_data = json.loads(patientJson)
if "cat" in student:
    print("Key exist in JSON data")
else
    print("Key doesn't exist in JSON data")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.