【发布时间】:2018-08-03 15:23:17
【问题描述】:
我有数据框,上面有坐标(记录的路线)。 数据框结构是这样的(有更多的列):
没有纬度经度高度速度课程日期时间等。
0 59.303758 18.078915 NaN 0.0 114.9 2017/04/01 13:21:48
1 59.303758 18.078915 -8.5 0.0 114.9 2017/04/01 13:21:49
2 59.303758 18.078915 -8.5 0.0 114.9 2017/04/01 13:21:50
.
.
列表还在继续……
我正在尝试从数据框中解析不需要的点。图片上的例子。红线代表数据框中的坐标点,我只想获取绿色字段上的点。
示例代码:
#north
y_1n=59.33551 #point 1 latitude
x_1n=18.02649 #point 1 longitude
y_2n=59.33327 #point 2 latitude
x_2n=18.04500 #point 2 longitude
#south
y_1s=59.33478 #point 3 latitude
x_1s=18.02645 #point 3 longitude
y_2s=59.33246 #point 4 latitude
x_2s=18.04422 #point 4 longitude
#
test = df1[(df1['Latitude'] <= y_1n) & (df1['Latitude'] >= y_2n) &
(df1['Latitude'] <= y_1s) & (df1['Latitude'] >= y_2s) &
(df1['Longitude'] >= x_1n) & (df1['Longitude'] <= x_2n) &
(df1['Longitude'] >= x_1s) & (df1['Longitude'] <= x_2s)
]
所以想法是只有这些预定义的 2 个北和 2 个南点(坐标点)内的数据被包含在新数据框中。
使用该代码,我设法解析了数据,但它远离南北点(仅包括一半街道)。所以它确实过度解析它或发生了一些奇怪的事情..
有没有更好或更有效的方法来做到这一点?
【问题讨论】:
-
df1 应该是单行吗?
-
df1 是 pandas DataFrame,具有多列和多行。
标签: python pandas gps coordinates