Consider the following example
data1 = [{'type': 'one', 'delta': '1', 'time': '2019'}, {'type': 'two', 'delta': '1', 'time': '2018'}]
data2 = [{'type': 'one', 'delta': '1', 'time': '2013'}, {'type': 'two', 'delta': '1', 'time': '2012'}]
dftest = pd.DataFrame({'weirdjson' : [data1, data2]})
dftest['normalcol'] = 1
dftest
Out[79]:
weirdjson normalcol time_type_one time_type_two
0 [{'type': 'one', 'delta': '1', 'time': '2019'}, {'type': 'two', 'delta': '1', 'time': '2018'}] 1 2019 2018
1 [{'type': 'one', 'delta': '1', 'time': '2013'}, {'type': 'two', 'delta': '1', 'time': '2012'}] 1 2013 2012
Essentially, I would like to create two columns time_type_one
and time_type_two
that each contain their corresponding time
value (for the first row: 2019
for type one
and 2018
for type two
).
How can I do that in Pandas? I have many rows so I am looking for something very efficient. Thanks!