Loading JSON data into pandas data frame and creating custom columns

Here is example JSON im working with.

    ":@computed_region_amqz_jbr4": "587",
    ":@computed_region_d3gw_znnf": "18",
    ":@computed_region_nmsq_hqvv": "55",
    ":@computed_region_r6rf_p9et": "36",
    ":@computed_region_rayf_jjgk": "295",
    "arrests": "1",
    "county_code": "44",
    "county_code_text": "44",
    "county_name": "Mifflin",
    "fips_county_code": "087",
    "fips_state_code": "42",
    "incident_count": "1",
    "lat_long": {
      "type": "Point",
      "coordinates": [

I have been able to pull out select columns I want except I'm having troubles with "lat_long". So far my code looks like:

col_titles = ['county_name', 'incident_count', 'lat_long']
df = df.reindex(columns=col_titles)

However 'lat_long' is added to the data frame as such: {'type': 'Point', 'coordinates': [-75.71107, 4...

I thought once I figured out how properly add the coordinates to the data frame I would then create two seperate columns, one for latitude and one for longitude.

Any help with this matter would be appreciated. Thank you.

#python #json #pandas

5 Likes2.00 GEEK