I want to get the centroids of my multipolygons using Python and GeoPandas. But when viewing the polygons and the centroids points on QGIS, the centroids are not inside the polygons.
Here is the code I used:
import geopandas as gpd
import pandas as pd
import sys
# Read the data
polygons = gpd.GeoDataFrame.from_file('mypolygons.shp')
temp=polygons.centroid
polygons['x'] = temp.x
polygons['y'] = temp.y
centroid=polygons[['x','y']]
gdf = gpd.GeoDataFrame(centroid, geometry=gpd.points_from_xy(centroid.x, centroid.y))
gdf.to_file("centroid/centroid.shp")
What is wrong?