Let's say I have an API response as:
{
"fact": {
"UP": [{
"SCODE": "CNB",
"SNAME": "Kanpur Central"
}, {
"SCODE": "JHS",
"SNAME": "Jhansi Junction"
}],
"MP": [{
"SCODE": "BPL",
"SNAME": "Bhopal Junction"
}, {
"SCODE": "JBP",
"SNAME": "Jabalpur Junction"
}]
}
}
I have to convert this into a dataframe which looks like below (expected output):
fact SCODE SNAME
UP CNB Kanpur Central
UP JHS Jhansi Junction
MP BPL Bhopal Junction
MP JBP Jabalpur Junction
My effort: I tried using json_normalize() but didn't reaches to expected output:
pd.json_normalize(response).apply(pd.Series.explode)