我在Jupyter笔记本中的后续行中收到错误
% matplotlib inline
Run Code Online (Sandbox Code Playgroud)
我使用的是Python 3.7版,ipyhton 7.0.1版
如何在groupby数据框上应用函数
给定数据框 df。
userid trip_id lat long
141.0 1.0 39.979547 116.306813
141.0 1.0 39.979558 116.306823
141.0 1.0 39.979575 116.306835
141.0 1.0 39.979587 116.306847
141.0 2.0 39.979603 116.306852
141.0 2.0 39.979612 116.306867
141.0 2.0 39.979627 116.306877
141.0 2.0 39.979635 116.306888
141.0 3.0 39.979645 116.306903
141.0 3.0 39.979657 116.306913
141.0 3.0 39.979670 116.306920
141.0 3.0 39.979682 116.306920
Run Code Online (Sandbox Code Playgroud)
我想计算每组数据帧的 Vincenty 距离。数据框分为 2 列,即 (userid,trip_id)
我可以通过给定的语句计算完整数据帧的 vincenty 距离
from geopy.distance import vincenty
df['lat_next'] = df['lat'].shift(-1)
df['long_next'] = df['long'].shift(-1)
df['Vincenty_distance'] = df.dropna().apply(lambda x: vincenty((x['lat'], x['long']), …Run Code Online (Sandbox Code Playgroud) 我有北京地区人员流动的GPS坐标。我想将地理空间划分为例如 2 平方公里(增量)的矩形网格,并访问网格内任何点的索引位置。单元格的大小不需要完全相同,在我的情况下可以使用近似值。
我的地理区域具有以下边界框坐标(纬度、经度)。
Bottom Left (x1,y1) = 39.77750000, 116.17944444
Top Left (x1,y2) = 40.04722222, 116.58888889
Bottom Right (x2,y1) = 39.77750000, 116.58888889
Top Right (x2,y2) = 40.04722222, 116.17944444
Run Code Online (Sandbox Code Playgroud)
这是 30 公里 x 34 公里的矩形区域。我心中的解决方案是取delta为2km,以delta增加纬度和经度值,直到达到上限。
要访问 GPS 点 p 的索引位置,令 BL 为矩形区域的左下点
Row = Distance [(p.lat,BL.long), (BL.lat, BL.long)] / delta
Column = Distance [(BL.lat,p.long), (BL.lat, BL.long)] / delta
Run Code Online (Sandbox Code Playgroud)
有没有更简单的方法或支持库来解决这个问题?最好是行和列(x,y)的组合,这样我就可以通过在笛卡尔坐标系中找到两个网格单元之间的距离来测量网格单元的紧密程度。示例图像和输入数据集可以让您清楚地了解描述。
链接中给出的输入数据集https://drive.google.com/file/d/1JjvS7igTmrtLA4E5Rs5D6tsdAXqzpYqX/view
我有这样的数据框
Transport Elapsed_Time gap_time gap_minutes
0 taxi 556.0 0 days 00:00:02 0.0
1 walk 95.0 0 days 00:53:34 53.0
2 taxi 44.0 0 days 02:02:00 122.0
3 taxi 2.0 0 days 17:05:56 1025.0
4 walk 73.0 0 days 00:14:31 14.0
5 boat 10.0 0 days 00:02:16 2.0
6 walk 34.0 0 days 00:00:42 0.0
7 boat 8.0 0 days 00:00:54 0.0
8 walk 37.0 0 days 00:07:25 7.0
9 boat 30.0 0 days 00:00:23 0.0
10 walk 105.0 0 days …Run Code Online (Sandbox Code Playgroud) 我喜欢使用多层 ConvLSTM 模型来检查我的模型。我的训练数据的形状是
trainX.shape (5000, 200, 4) # testX.shape (2627, 200, 4)
Run Code Online (Sandbox Code Playgroud)
以下是我的工作正常的代码
print('trainX.shape', trainX.shape) # trainX.shape (5000, 200, 4)
print('testX.shape', testX.shape) # testX.shape (2627, 200, 4)
# reshape into subsequences (samples, time steps, rows, cols, channels)
samples, n_features = trainX.shape[0], trainX.shape[2]
n_steps, n_length = 8, 25
trainX = trainX.reshape((samples, n_steps, 1, n_length, n_features)) #
print('trainX.shape', trainX.shape) # (5000, 8, 1, 25, 4)
testX = testX.reshape((testX.shape[0], n_steps, 1, n_length, n_features))
print('testX.shape', testX.shape) # (2627, 8, 1, 25, 4)
# define …Run Code Online (Sandbox Code Playgroud)