AttrributeError with dataframe when processing google locations json data

问题描述 投票:0回答:0

我正在尝试处理包含谷歌位置历史数据的 JSON 文件,并试图将所有数据点放入数据框中。我正在使用此代码作为参考 (https://github.com/nurkiewicz/google-location-history/blob/master/Google%20location%20history.ipynb)。但是,我遇到了这个错误:

return object.getattribute(self, name) AttributeError: 'DataFrame' 对象没有属性 'locations'

这是我的代码:

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"))

这是位置历史的样子: enter image description here

我还是 Python 的新手,所以我不确定如何解决这个问题?

我尝试调试代码以通过 json,但不确定出了什么问题。

python pandas geopandas
© www.soinside.com 2019 - 2024. All rights reserved.