0

After a Pandas-update, I get a bunch of warnings for append to be depecated. This is the code to analyze a gpx file:

import pandas    as bib_pandas
gpx = mod_gpxpy.parse(open(dir_file))   # read GPX-File
gpx_points = gpx.tracks[0].segments[0].points
data_frame = bib_pandas.DataFrame(columns=["lon", "lat", "elev", "time"])
for point in gpx_points:
    # data_frame = data_frame.append({"lon": point.longitude, "lat": point.latitude, "elev": point.elevation, "time": point.time}, ignore_index=True) # OLD code, works, with warning!
    bib_pandas.concat([data_frame, {"lon": point.longitude, "lat": point.latitude, "elev": point.elevation, "time": point.time}], ignore_index=True)  # NEW Code, ERROR

As shown above, I tried to use concat instead of append, but this gives an error:

TypeError: cannot concatenate object of type '<class 'dict'>'; only Series and DataFrame objs are valid

With my old code, thedataframe looks like this:

           lon        lat   elev                      time
0    14.936605  55.498336  421.0 2020-08-20 07:15:39+00:00
..         ...        ...    ...                       ...
416  13.936569  55.498304  421.0 2020-08-20 08:12:16+00:00
[417 rows x 4 columns]

How can I fix this?

1 Answer 1

1

You need neither append nor concat, you can use:

l = [{"lon": point.longitude, "lat": point.latitude,
      "elev": point.elevation, "time": point.time}
     for point in gpx_points]

data_frame = bib_pandas.DataFrame(l)
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. looks fine for a test-file. BUT you missed the , ignore_index=True. How can I bring it back?
You shouldn't need this, the index should already be a range (0 -> n), no?
May be you're right. The original author of the code (search within the page ígnore_index) used it, so I'd feel better to have it back ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.