tkrajina / gpxpy

gpx-py is a python GPX parser. GPX (GPS eXchange Format) is an XML based file format for GPS tracks.
Apache License 2.0
993 stars 223 forks source link

unhashable type: 'SimpleTZ' when buliding pandas dataframe #183

Closed turbomam closed 4 years ago

turbomam commented 4 years ago

Thanks for this package

I'm cross-posting from Stack Overflow

I'm getting

TypeError: unhashable type: 'SimpleTZ'

when data is a list of trackpoints and I

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)

I'm following this tutorial: https://towardsdatascience.com/how-tracking-apps-analyse-your-gps-data-a-hands-on-tutorial-in-python-756d4db6715d

SimpleTZ is something you created, right? Is there a way for me to use a different time zone system or to omit the time zone when running gpxpy.parse? I looked at the source, and th eonly other argumetns I see ar efor GPX version (and character encoding?)

turbomam commented 4 years ago

I get the sense that this is more of a pandas problem than a gpxpy problem. Or even a general timezone problem?

In any case, this slightly different approach from https://ocefpaf.github.io/python4oceanographers/blog/2014/08/18/gpx/ does work

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)