I have pandas dataframe in which one column has its entries in nested json form like this as shown below
Date ID Request
12/01/2020 123 {"requestChannel":"amazon","userID":"123@abc.com","Context":"
{\"ref_id\":[\"1-123456\"],\"type\":\"Apparels\","formJson":null,"additionalData":null},"additional":
{"ref_id":"1-12345","last_saved":"order"}}
and thousands of rows like this in same format
I want to take out just the "type" in nested second json on the basis of "ID" like this:
Output
Date ID Request
12/01/2020 123 Apparels
What i am trying to do is to parse the Request column of dataframe as json iterate over entire row and take the "type" key from second "Context" json and take the key type
for name in range(data.shape[0]):
output_json=data['Request'][name]
json_data=json.loads(output_json)
try:
parse_json=json.loads(json_data['Request'])
value_to_insert=''
for json_key in parse_json:
value_to_insert+=str(json_key + '--'+ str(parse_json[json_key])+', '+'\n')
But my code is not changing the dataframe series to correct json form and also iterating over the entire rows is taking a lot of time. Any idea on optimized solution would be appreciated