0

I'm trying to process a JSON file containing google location history data and am trying to put all the data points into a dataframe. I am using this code as reference (https://github.com/nurkiewicz/google-location-history/blob/master/Google%20location%20history.ipynb). However, I encounter this error:

return object.getattribute(self, name) AttributeError: 'DataFrame' object has no attribute 'locations'

This is my code:

import pandas as pd
import numpy as np
import geopandas as gp
import shapely.geometry as sg
import datetime as dt
from matplotlib import cm
from matplotlib.lines import Line2D
   

def parse_json(json):
    points = [sg.Point(xy) for xy in zip(json.locations.apply(lambda x: x["longitudeE7"] / 10000000),
                                     json.locations.apply(lambda x: x["latitudeE7"] / 10000000))]
    df = gp.GeoDataFrame(geometry=points)
    return df

df = parse_json(pd.read_json("2022_MAY.json"))

This is what the location history looks like: enter image description here

I'm still new to Python so I'm unsure how to resolve this issue?

I tried debugging the code to go through the json but wasn't really sure what was going wrong.

Michael Delgado
  • 13,789
  • 3
  • 29
  • 54
  • When asking about errors, please always include the [full traceback](//realpython.com/python-traceback). That said, it’s clear the issue is just that you don’t have a column in the data called “locations”. The match must be exact, so it could be a capitalization issue. Check your data and make sure to use the actual column name. – Michael Delgado Feb 23 '23 at 00:01
  • Does this answer your question? [How to resolve AttributeError: 'DataFrame' object has no attribute](https://stackoverflow.com/questions/38134643/how-to-resolve-attributeerror-dataframe-object-has-no-attribute) – Michael Delgado Feb 23 '23 at 00:01
  • 1
    The JSON sample that you showed (via image) does not contain a member called "locations". – Tim Roberts Feb 23 '23 at 01:25
  • Oh ok, I think I understand now. I think my json was different than the one used in my reference and did not contain the "locations" member so I replaced that and it fixes the issue. Thank you for the help! – Karthik Prasad Feb 27 '23 at 02:38

0 Answers0