我正在尝试使用代码(在下面的链接中提供)将纬度/经度坐标映射到纽约市行政区:
https://www.kaggle.com/muonneutrino/nyc-taxis-eda-and-mapping-position-to-borough
我正在处理低内存本地 Jupyter 环境,因此我已将带有 Taxi lat/long 数据的大型 .csv 文件导入到 dask 数据框中。
首先,我使用此处找到的 2016 年 6 月 Yellow Cab 数据创建了一个 dask 数据框:并将子集设置为 atest_day
以使集合更小:
import pandas as pd
import dask.dataframe as dd
import dask.array as da
from dask.distributed import Client
client = Client(processes=False)
%pylab inline
cols= ['pickup_longitude', 'pickup_latitude', 'tpep_pickup_datetime',]
ddf = dd.read_csv('yellow_tripdata_2016-06.csv',blocksize=13e7,assume_missing=True, usecols=cols)
ddf['tpep_pickup_datetime'] = dd.to_datetime(ddf.tpep_pickup_datetime, errors='ignore')
ddf['pickup_day'] = ddf.tpep_pickup_datetime.dt.day
td = ddf.loc[ddf.pickup_day == 10]
td = td.rename(columns={'pickup_longitude':'plon',
'pickup_latitude':'plat'} )
我首先声明值 latmin、lonmin、latmax 和 lonmax 并创建 numpy 数组 map_tracts:
xmin = 40.48
ymin = -74.28
xmax = 40.93
ymax = -73.65
dlat = (xmax-xmin) / 199
dlon = (ymax-ymin) / 199
td['lat_idx'] = (np.rint((td['plat'] - latmin) / dlat))
td['lon_idx'] = (np.rint((td['plon'] - lonmin) / dlon ))
map_tracts = ([[34023007600, 34023007600, 34023007500, 34031246300,
34031246300, 34031246300],
[34023007600, 34023007600, 34023007600, 34031246300,
34031246300, 34031246300],
[34023007600, 34023007600, 34023007600, 34031246300,
34031246300, 34031246300],
[ 0, 0, 0, 36059990200,
36119007600, 36119007600],
[ 0, 0, 0, 36059990200,
36059990200, 36119007600]])
然后我尝试运行一个 dask 数组 where 子句:
td['pu_tracts'] = da.where(((xmin < td.plat < xmax) &
(ymin < td.plong < ymin)),
(map_tracts[td.lat_idx, td.lon_idx]),0)
但是收到一个错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-24-5228e3ec653a> in <module>
----> 1 td['pu_tracts'] = np.where(((xmin < td.plat < xmax) &
2 (ymin < td.plong < ymin)),
3 (map_tracts[td_day.lat_idx, td.lon_idx]),0)
~/anaconda3/lib/python3.7/site-packages/dask/dataframe/core.py in __bool__(self)
441 raise ValueError("The truth value of a {0} is ambiguous. "
442 "Use a.any() or a.all()."
--> 443 .format(self.__class__.__name__))
444
445 __nonzero__ = __bool__ # python 2
ValueError: The truth value of a Series is ambiguous. Use a.any() or a.all().
这是一个问题吗?