Trying to flattened JSON data in to pandas dataframe generated from API response.
In below code, i flattened raw json data in to different columns using Json_normlize
raw_json = json_normalize(data["data"],sep="_")
Pages contains JSON data mentioned in col1 & col2.Using apply(pd.Series), split pages data in to 2 different columns named col1 & col2
raw_pages=raw_json['pages'].apply(pd.Series)
Now, I need help in extracting (id, choice_id,row_id,simple_text & heading) from col1 & col2.
Col1:
{
'id': '124550266',
'questions': [
{
'id': '471362125',
'answers': [
{
'tag_data': [
{
'hexcolor': '671E75',
'label': 'sm_processed_q',
'tag_type': 'sentiment'
},
{
'hexcolor': '671E75',
'label': 'sm_processed_q',
'tag_type': 'sentiment'
}
],
'simple_text': '9999999999'
}
],
'family': 'open_ended',
'subtype': 'single',
'heading': 'Please confirm your registered number with us'
},
{
'id': '471362121',
'answers': [
{
'choice_id': '3114700230',
'row_id': '3114700224',
'simple_text': '5'
}
],
'family': 'matrix',
'subtype': 'rating',
'heading': 'How likely is it that you would recommend xxxxx to a friend or colleague?'
}
]
}
COl2:
{
'id': '124550267',
'questions': [
{
'id': '471362124',
'answers': [
{
'choice_id': '3114700246',
'row_id': '3114700251'
},
{
'choice_id': '3114700247',
'row_id': '3114700254'
},
{
'choice_id': '3114700248',
'row_id': '3114700255'
},
{
'choice_id': '3114700248',
'row_id': '3114700257'
},
{
'choice_id': '3114700249',
'row_id': '3114700259'
}
],
'family': 'matrix',
'subtype': 'rating',
'heading': 'Dear customer how much would you rate us)'
},
{
'id': '471362122',
'answers': [
{
'tag_data': [
{
'hexcolor': '05467E',
'label': 'sm_positive',
'tag_type': 'sentiment'
}
],
'simple_text': 'More variety should be addwd'
}
],
'family': 'open_ended',
'subtype': 'essay',
'heading': 'Dear Customer,<br>Kindly help us, by providing your valuable suggestions or feedback'
}
]
}