I have an interesting problem, and I'm wondering if there's a concise, pythonic (pandastic?) way to do this, rather than iterating over rows of a data frame.
Take a DataFrame with one field that is a json encoding of information:
Name Data
0 Joe '[{"label":"a","value":"1"},{"label":"b","value":"2"}]'
1 Sue '[{"label":"a","value":"3"},{"label":"c","value":"4"}]'
2 Bob '[{"label":"b","value":"4"},{"label":"d","value":"1"}]'
I want to expand the json field to be data fields, unioning the different column headers, to get this:
Name Data a b c d
0 Joe '[{"label":"a"... 1 2
1 Sue '[{"label":"a"... 3 4
2 Bob '[{"label":"b"... 4 1
The blanks are missing values. I know I can use read_json to create data frames from the json field, but then I want to re-flatten these data frames into extra columns of the original data set.
So, is there an elegant way to do this without iterating over the various rows of the data frame? Any help would be appreciated.