trackintel icon indicating copy to clipboard operation
trackintel copied to clipboard

ENH: Returns of generate_locations() function

Open HaojunCai opened this issue 3 years ago • 2 comments

For the returns stp_cls and loc_cls of generate_locations() function, I would like the possibility to have the coordinates of clustered locations (loc_cls) assigned to each stay point (stp_cls), so that I could further extract mobility features on the basis of stp_cls data. It could be achieved by stp_cls = stp_cls.join(loc_cls, on="location_id", lsuffix='user_id') and could be set by default False to avoid data redundancy.

HaojunCai avatar Jun 16 '21 13:06 HaojunCai

Hi Haojun,

Thanks for raising up this issue. Trackintel now does not provide the possibility to join the information of different data models as internal functions. For joining staypoint with location level information, I would recommend using:

stps.reset_index().merge(locs, left_on=["location_id", "user_id"], right_on=["id", "user_id"]).set_index("id"))

This line resets the index of the input staypoint, merge the two dataframes on location_id/id and user_id, and sets back the id column for the staypoint index.

We are now planning to include helper functions in trackintel to join staypoint + location and tripleg + trip. Thanks again for raising our awareness :).

hongyeehh avatar Jul 05 '21 16:07 hongyeehh

@hong2223 Should we create an assignable issue for these helper functions where we collect what is needed and close this issue? (I would like to have a way to join location IDs to trips :-) )

henrymartin1 avatar Jul 28 '21 15:07 henrymartin1