I've been struggling to complete this exercise (Exercise 2 Problem 3) which you guys can refer to this link. A reminder that the kruger_points.shp is obtained from Exercise 2 Problem 2. Here's the specific problem that I'm trying to tackle.
Here's the head of the original dataframe (kruger_points.shp).
I'm trying to create a new geodataframe which the data is grouped according to userid and the timestamp is sorted from oldest to most recent. The code is written down below:
sorted_test = {"userid": [], "timestamp":[]}
for name, group in grouped_by_users:
iterate_for_userid = group["userid"].sort_values(ascending = True)
sorted_test["userid"].append(iterate_for_userid)
iterate_for_timestamp = group["timestamp"].sort_values(ascending = True)
sorted_test["timestamp"].append(iterate_for_timestamp)
sorted_df = geopandas.GeoDataFrame(sorted_test)
sorted_df.head()
When I checked the new dataframe, I realised that the row contained everything instead of timestamp and userid only.
Therefore, what is the proper way to solve this problem?