简体   繁体   English

给定gps点的速度,如何标准化Node ID的速度

[英]how to normalise velocity for Node ID given the speed of gps points

I have a column of GPS map matched points with road ID'S along with speed of the vehicle at these GPS points, how do I normalize the speed for each of this road id ID? 我有一列具有道路ID的GPS地图匹配点以及这些GPS点处的车辆速度,如何对每个道路ID的速度进行归一化?

ID  LAT           LONG          SPEED
0   72.5896       72.893     60KM/H
0   73.5888       72.899     50KM/H
0   89.5366       78.822     60KM/H
1   99.8576       88.6115    50KM/H
1   120.1515      128.2225   30KM/H
1   -88.515       -51.5151   30KM/H

enter image description here 在此处输入图片说明

Here you go with usage of pandas and numpy: 在这里,您可以使用pandas和numpy:

=^..^= = ^ .. ^ =

import pandas as pd
import numpy as np
from io import StringIO

# create raw data
raw_data = StringIO(
"""ID LAT LONG SPEED
0 72.5896 72.893 60KM/H
0 73.5888 72.899 50KM/H
0 89.5366 78.822 60KM/H
1 99.8576 88.6115 50KM/H
1 120.1515 128.2225 30KM/H
1 -88.515 -51.5151 30KM/H""")

# load data into data frame
df = pd.read_csv(raw_data, sep=' ')

# replace string
df['SPEED'] = df['SPEED'].str.replace(r'KM/H', '')

# normalize function
def normalize_data(i):
    selected_data = df.loc[df['ID'] == i]
    selected_data = selected_data.copy()

    selected_data['normalized'] = (selected_data['SPEED'].astype(np.int) - selected_data['SPEED'].astype(np.int).min()) / (
                selected_data['SPEED'].astype(np.int).max() - selected_data['SPEED'].astype(np.int).min())

    return selected_data

# loop over ID numbers and normalize data
frames = []
for i in range(0, df['ID'].max()+1):
    selected_data = normalize_data(i)
    frames.append(selected_data)

# concat frames
result = pd.concat(frames)

Output: 输出:

   ID       LAT      LONG SPEED  normalized
0   0   72.5896   72.8930    60         1.0
1   0   73.5888   72.8990    50         0.0
2   0   89.5366   78.8220    60         1.0
3   1   99.8576   88.6115    50         1.0
4   1  120.1515  128.2225    30         0.0
5   1  -88.5150  -51.5151    30         0.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM