I request data from a table in a database and each line comes as a dictionary like this one :
{
"timestamp" : 1234657890,
"prices" : {
"AAA" : 111,
"BBB" : 222,
...
"ZZZ" : 999
}
}
From all those lines i wanted to create a dataframe like this:
Timestamp AAA BBB ... ZZZ
1234657890 111 222 ... 999
1234567891 110 223 ... 997
...
1324657899 123 208 ... 1024
So i did :
rawData = database_request()
listPrices = []
for row in rawData
tmp = {'timestamp': row['timestamp']}
tmp.update({name : price for name,price in row['prices'].items()})
listPrices.append(tmp)
df = pd.DataFrame(listePrices)
So i was wondering if there were a more pythonic way to do this ?
prices
andtimestamps
in the dictionary? \$\endgroup\$pd.json_normalize
here. \$\endgroup\$