0

I am new to pandas and trying to use query on to filter by contact.account.accountName value in this json DataFrame

            "id": "265680000013269026",
            "ticketNumber": "2400",
            "layoutId": "265680000000074011",
            "phone": null,
            "subject": "test",
            "status": "Open",
            "statusType": "Open",
            "createdTime": "2021-11-03T14:48:18.000Z",
            "channel": "Email",
            "dueDate": null,
            "responseDueDate": null,
            "commentCount": "0",
            "sentiment": null,
            "threadCount": "1",
            "departmentId": "265680000000006907",
            "contactId": "265680000007844038",
            "teamId": null,
            "contact": {
                "firstName": null,
                "lastName": "income",
                "type": null,
                "account": {
                    "accountName": "ACC",
                    "website": null,
                    "id": "265680000000547037"
                },
                "id": "265680000007844038"
            },
            "channelCode": null

The Dataframe

     ticketNumber              email              createdTime          contact.account.accountName
0       2400               test@email.com      2021-11-03T14:48:18.000Z                  ACC

here is the code

df = pd.json_normalize(json_data)
filteredData = df.query('contact.account.accountName == "ACC"')

but i get this error

pandas.core.computation.ops.UndefinedVariableError: name 'contact' is not defined

can someone tell me what I'm doing wrong with with this code ?

0 Answers0