python - 不可散列的类型:将 GPS 数据加载到 pandas 数据帧时的“SimpleTZ”
问题描述
我一直在用 R 解析一些 GPS 轨迹,并认为我会在 Python 中尝试同样的事情,尽管我的 Python 技能要弱得多。
一切顺利,直到
df = pd.DataFrame(columns=['lon', 'lat', 'alt', 'time'])
for point in data:
df = df.append({'lon': point.longitude, 'lat' : point.latitude, 'alt' : point.elevation, 'time' : point.time}, ignore_index=True)
这给了我一个错误,以
TypeError:不可散列的类型:'SimpleTZ'
一个 GPS 点如下所示:
GPXTrackPoint(40.08285088, -75.19106663, elevation=144.4, time=datetime.datetime(2019, 10, 22, 18, 36, 41, tzinfo=SimpleTZ("Z")))
我在 Windows 上通过 Anaconda 在 Jupyter 中使用 Python 3.7.0。
我更喜欢用区域解析时间戳,但如果这会让事情变得更容易,我愿意丢弃区域。
解决方案
我觉得这更像是一个熊猫问题而不是 gpxpy 问题。甚至是一般的时区问题?
无论如何,这种与https://ocefpaf.github.io/python4oceanographers/blog/2014/08/18/gpx/略有不同的方法确实有效
data = []
gpx = gpxpy.parse(open(gpxfile))
track = gpx.tracks[0]
segment = track.segments[0]
for point_idx, point in enumerate(segment.points):
data.append([point.longitude, point.latitude,
point.elevation, point.time, segment.get_speed(point_idx)])
columns = ['Longitude', 'Latitude', 'Altitude', 'Time', 'Speed']
df = DataFrame(data, columns=columns)
推荐阅读
- angular - Angular Universal - 在查看源代码中看不到标题,但在检查期间可以看到
- visual-studio-code - 如何修改 VSCode 的 javascript 格式化程序用于设置行继续缩进的样式?
- d3.js - D3 data() 调用不会触发元素上的 exit() 但 enter() 有效
- javascript - 尝试访问 json 内容并以网格方式显示
- python - Keras:从自定义生成器中获取单个批次
- jenkins - Jenkins 围绕管道共享库脚本触发包装器
- opencart - 如何在 Opencart 前端接收模块 ID
- python - 通过每组两个数据元素创建行的有效方法是什么?
- groovy - 在 groovy 中使用带反斜杠的 sed
- distance - 距离采样代码,出现我不知道如何解决的错误