Why is my output is in Pandas Series after creating LineStrings from grouped ID? /u/mfirdaus_96 Python Education

I want to group the points by userid then create a LineString for each userid. Here’s the GeoDataframe.

My goal is to store the results in a Geodataframe. Here’s the code which I actually obtained from one question in GIS Stack Exchange several years ago:

line_strings = df.groupby("userid")["geometry"].apply(lambda x: LineString(x.tolist()) if x.size > 1 else x.tolist()

However, the output is in Series instead.

So if I want to convert it back to GeoDataFrame, I unable to do so because it said TypeError: Input must be valid geometry objects: [<POINT (900800.126 7174374.539)>]

So I want to know where is my mistake?

P.S.: If you want to try out with the actual data, you can check out this link: https://github.com/Automating-GIS-processes-II-2024/exercise-2/blob/main/Exercise-2-problem-3.ipynb

I’m learning how to use Python in GIS context using this course & currently stuck at Problem No.3 part C (You need to create the shapefile from Problem 2 if you want to try with actual data)

submitted by /u/mfirdaus_96
[link] [comments]

​r/learnpython I want to group the points by userid then create a LineString for each userid. Here’s the GeoDataframe. My goal is to store the results in a Geodataframe. Here’s the code which I actually obtained from one question in GIS Stack Exchange several years ago: line_strings = df.groupby(“userid”)[“geometry”].apply(lambda x: LineString(x.tolist()) if x.size > 1 else x.tolist() However, the output is in Series instead. So if I want to convert it back to GeoDataFrame, I unable to do so because it said TypeError: Input must be valid geometry objects: [<POINT (900800.126 7174374.539)>] So I want to know where is my mistake? P.S.: If you want to try out with the actual data, you can check out this link: https://github.com/Automating-GIS-processes-II-2024/exercise-2/blob/main/Exercise-2-problem-3.ipynb I’m learning how to use Python in GIS context using this course & currently stuck at Problem No.3 part C (You need to create the shapefile from Problem 2 if you want to try with actual data) submitted by /u/mfirdaus_96 [link] [comments] 

I want to group the points by userid then create a LineString for each userid. Here’s the GeoDataframe.

My goal is to store the results in a Geodataframe. Here’s the code which I actually obtained from one question in GIS Stack Exchange several years ago:

line_strings = df.groupby("userid")["geometry"].apply(lambda x: LineString(x.tolist()) if x.size > 1 else x.tolist()

However, the output is in Series instead.

So if I want to convert it back to GeoDataFrame, I unable to do so because it said TypeError: Input must be valid geometry objects: [<POINT (900800.126 7174374.539)>]

So I want to know where is my mistake?

P.S.: If you want to try out with the actual data, you can check out this link: https://github.com/Automating-GIS-processes-II-2024/exercise-2/blob/main/Exercise-2-problem-3.ipynb

I’m learning how to use Python in GIS context using this course & currently stuck at Problem No.3 part C (You need to create the shapefile from Problem 2 if you want to try with actual data)

submitted by /u/mfirdaus_96
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *