0

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.

enter image description here

Here's the head of the original dataframe (kruger_points.shp). enter image description here

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.

enter image description here

Therefore, what is the proper way to solve this problem?

2
  • Does my answer work?
    – Bera
    Commented Jan 23 at 6:02
  • Sorry for the late reply. I'm unable to change the 29-2-2023 because the value is not yet in datetime value. When I tried to convert to datetime, I can't because of the incorrect leap year date. Commented Jan 25 at 0:10

0

Your Answer

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