Question:
The zendesk api returns fields as a list of dictionaries but each list is a single record. I’m wondering if there is a better way to turn it all into a dataframe. If it’s a dictionary of dictionaries thenjson_normalize
takes care of it with no problem.Caveat: not all records will have the same field IDs
Sample data:
ticket_id | customer_id | created_at | custom_fields | group_id | |
---|---|---|---|---|---|
0 | 4 | 8 | 2022-05-01 | [{‘id’: 15, ‘value’: ‘website’}, {‘id’: 16, ‘v… | 42 |
My current, probably ill-advised, solution is:
ticket_id | customer_id | created_at | group_id | 15 | 16 | 23 | |
---|---|---|---|---|---|---|---|
0 | 4 | 8 | 2022-05-01 | 42 | website | broken | None |
My worry is that i need to do this to ~25,000 records and this seems like it will be both slow and brittle (prone to breaking).
Answer:
You should wrangle the data/dictionary first and only then construct a DataFrame with it. It will make your life easier and is faster than trying to manipulate the data withpandas
i.e. after the DataFrame is created.If you have better answer, please add a comment about this, thank you!