原文地址: sh truck bootcamp
在前一篇文章中,我们简单的介绍了使用 Arctern分析纽约出租车的的数据。在那个例子中,出租车的数据只有上车点和下车点的数据,没有完整的轨迹数据,所以整个分析显得有点意犹未尽。
在这篇文章中,我们使用上海市的渣土车数据,该数据包含完整的轨迹数据,所有我们可以实现类似高德地图的功能,分析在特定时间段内哪些道路比较拥堵。
废话不多说,以下为原文。
环境准备
-
安装 Arctern
-
安装 Jupyter
在上一步中的
arctern_env
环境中执行以下命令安装 Jupyter Notebook:$ conda install -c conda-forge notebook
-
安装依赖库
在
arctern_env
环境中执行以下命令安装相关依赖库:$ pip install keplergl matplotlib
下载数据
我们需要下载 200 多万条上海渣土车数据和上海市的地形数据图数据,默认将其下载至 /tmp
下:
$ cd /tmp
# 下载并解压上海渣土车数据
$ wget https://github.com/arctern-io/arctern-bootcamp/raw/master/shtruck/file/20181016.zip
$ unzip 20181016.zip
# 下载上海市的地形数据图
$ wget https://github.com/arctern-io/arctern-bootcamp/raw/master/shtruck/file/sh_roads.csv
运行 jupyter-notebook
下载 arctern_shtruck_bootcamp.ipynb 文件,在 arctern_env
环境中运行 jupyter notebook:
$ wget https://raw.githubusercontent.com/zilliztech/arctern-bootcamp/master/shtruck/arctern_shtruck_bootcamp.ipynb
# 运行 jupyter notebook
$ jupyter notebook
在 jupyter 网页中打开 arctern_shtruck_bootcamp.ipynb 文件,就可以开始运行代码了。
上海渣土车数据分析示例
1. 数据加载
加载上海市渣土车运行轨迹数据,原数据共 8 列,此处只读取本文分析所需要的 4 列:车牌号、时间、经度、维度。
import pandas as pd
import arctern
from arctern import GeoSeries
sh_columns=[
("plate_number","string"),
("pos_time","string"),
("pos_longitude","double"),
("pos_latitude","double"),
("pos_direction0","double"),
("pos_direction1","double"),
("pos_direction2","double"),
("pos_direction3","double")
]
sh_select_columns={
"plate_number",
"pos_time",
"pos_longitude",
"pos_latitude"
}
sh_schema={
}
sh_use_cols=[]
sh_names=[]
for idx in range(len(sh_columns)):
if sh_columns[idx][0] in sh_select_columns:
sh_schema[sh_columns[idx][0]] = sh_columns[id