我有一個包含 x、y、資料列的資料框。我有一個像這樣的多邊形坐標串列:polygon=[x1,y1,x2,y2,x3,y3,x4,y4]
我想過濾掉多邊形外帶有 (x,y) 的所有資料幀行
df.columns=['x','y','data']
polygon=[x1,y1,x2,y2,x3,y3,x4,y4]
df_1= df inside polygon
如何實作最后一行?謝謝
uj5u.com熱心網友回復:
見勻稱:
from shapely.geometry import Point
from shapely.geometry.polygon import Polygon
df['point'] = df.apply(lambda row: Point(row['x'],row['y']),axis=1)
polygon = Polygon([(x1,y1), (x2,y2), (x3,y3), (x4,y4)])
df_1 = df[df['point'].apply(polygon.contains)].copy()
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/403713.html
標籤:
上一篇:如何獲取GoogleCloudPlatformblob的唯一識別符號?
下一篇:如何僅從字典中提取選定的值?
