Tuesday, August 15, 2017

Reading JSON file into Pandas DataFrame

I wanted to read in a JSON object on a python pandas dataframe for further processing. So, I tried the default pandas read JSON method: read_json('file.json'), but I got just the JSON strings returned in the dataframes's row as seen below. That isn't what I was expecting....



Fortunately for me, pandas has a solution for this in its json_normalize class that “Normalize” semi-structured JSON data into a flat table.


So, I read the JSON file and applied the "json_normalize()" class and boom my semi-structured JSON data was converted into a flat table as seen above.

That was it!

No comments:

Post a Comment