如何根据值之间的距离将数据集(CSV)分为子集或添加属性?

时间:2019-06-04 11:10:26

标签: python dataframe

我正在研究车辆轨迹的数据集(CSV)。我需要将整个数据集划分为多个部分,每个部分仅覆盖200英尺的距离

"Vehicle ID","Frame ID","Total Frames","Global Time","Local X","Local Y","Global X","Global Y","V_Len","V_Width","V_Class","V_Vel","V_Acc","Lane_ID","Pre_Veh","Fol_Veh","Spacing","Headway"

2,13,437,1118846980200,16.467,35.381,6451137.641,1873344.962,14.5,4.9,2,40.00,0.00,2,0,0,0.00,0.00
2,14,437,1118846980300,16.447,39.381,6451140.329,1873342.000,14.5,4.9,2,40.00,0.00,2,0,0,0.00,0.00 
2,17,437,1118846980600,16.385,51.381,6451148.395,1873333.115,14.5,4.9,2,40.00,0.00,2,0,0,0.00,0.00 
69,208,504,1118846999700,16.455,174.923,6451232.437,1873241.783,12.5,5.0,2,31.41,-7.71,2,71,78,75.46,2.40
1693,4861,466,1118847465000,39.652,231.988,6451255.460,1873184.174,8.5,6.0,2,33.05,-11.20,4,1689,1699,91.34,2.76
2615,8256,919,1118847804500,17.871,1805.110,6452448.583,1872154.574,16.0,6.9,2,19.98,-0.28,2,2608,2618,45.52,2.28
2616,7597,714,1118847738600,42.468,408.007,6451382.402,1873059.356,17.0,7.4,2,38.35,8.50,4,2604,2620,67.36,1.76
3109,7184,510,1118847697300,57.417,2082.094,6452636.527,1871944.862,14.0,5.9,2,50.00,0.00,5,0,2325,0.00,0.00

我尝试了两点,给出了大约200英尺的距离,并设置为数据框的遮罩。但这并不成立。

sx=16.467;
sy=35.381;
ex=15.64;
ey=238.909;

maskdist=((df['Local X'] > sx) & (df['Local X'] <= ex) & (df['Local Y'] > sy) & (df['Local Y']) <= ey)

dist_df=df.copy()
dist_df=dist_df.loc[maskdist]

要么我必须保留为单独的数据集,要么需要添加一个标记节ID的属性(例如,节1- 0-200ft,2-201-400ft,3-401-600ft ... 10-1800- 2000英尺。)因此,根据区段ID,可以进一步分析数据帧。

0 个答案:

没有答案