I am loading a json file with nested values. Here is how it loads:
>>> pd.read_json('/Users/david/Desktop/validate_headers/json/example_array2.json')
address firstname lastname zip_code
0 {'state': 'MI', 'town': 'Dearborn'} Jimmie Barninger 12345
1 {'state': 'CA', 'town': 'Los Angeles'} John Doe 90027
I would like to flatten the nested object, so that my end dataframe looks like this:
firstname lastname zip_code address.state address.town
Jimmie Barninger 12345 MI Dearborn
John Doe 90027 CA Los Angeles
How would I do this, that is, if the dataframe column is an object, split that column up into multiple columns (and do so until there are no json objects left)?