I have a json file (sample below). I am trying to create a Dataframe from this using python: JSON:
{"data": {
"A": [{
"CREATION_DATE": "1482105600",
"SOURCE_COUNT": "0"
},
{
"CREATION_DATE": "1482105600",
"SOURCE_COUNT": "0"
} ],
"B": [{
"CREATION_DATE": "1487808000",
"SOURCE_COUNT": "1048"
},
{
"CREATION_DATE": "1487894400",
"SOURCE_COUNT": "1103"
} ]
}
}
When I am trying to convert it into a dataframe:
My Code:
import json
file = 'mysample.json'
with open(file) as train_file:
dict_train = json.load(train_file)
# converting json dataset from dictionary to dataframe
train = pd.DataFrame.from_dict(dict_train, orient='index')
train.reset_index(level=0, inplace=True)
Output:
index A B
0 data [{'CREATION_DATE': '1482105600', 'SOURCE_COUNT... [{'CREATION_DATE': '1487808000', 'SOURCE_COUNT...
Instead I am looking to convert this into a dataframe which looks like below:
system CREATION_DATE SOURCE_COUNT
A 1482105600 0
A 1482105600 0
B 1487808000 1048
B 1487894400 1103
How to modify my code to get to the expected output?