我有以下代码:
def parallelUpdateJSON(submatrix):
with open('geo.geojson') as f:
data = json.load(f)
for feature in data:
currentfeature = submatrix[(submatrix['SId']==feature['properties']['cellId'])]
if (len(currentfeature) > 0):
feature['properties'].update({"style": {"opacity": currentfeature.AllActivity.item()}})
else:
feature['properties'].update({"style": {"opacity": 0}})
pool = Pool()
pool.map(parallelUpdateJSON, submatrix)
pool.close()
pool.join()
此处,submatrix
是pandas
数据框:
submatrix.dtypes
Index 1200240
SId 1200240
Weekday 1200240
Hour 1200240
Internet 1200240
SmsIn 1200240
SmsOut 1200240
CallIn 1200240
CallOut 1200240
AllActivity 1200240
dtype: int64
我得到错误,我在某处使用字符串作为索引而不是整数,但我似乎无法弄明白,在哪里。错误是TypeError: string indices must be integers
。你能帮我找到我做错的事吗?
完整堆栈跟踪:
---------------------------------------------------------------------------
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/lib/python3.5/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/usr/lib/python3.5/multiprocessing/pool.py", line 44, in mapstar
return list(map(*args))
File "<ipython-input-19-3d3715e97af2>", line 5, in parallelUpdateJSON
currentfeature = submatrix[(submatrix['SId']==feature['properties']['cellId'])]
TypeError: string indices must be integers
"""
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<ipython-input-20-d6121ed2750b> in <module>()
----> 1 writeGeoJSON(6, 15, baseline)
<ipython-input-19-3d3715e97af2> in writeGeoJSON(weekdaytopredict, hourtopredict, predictionmatrix)
16 #func = partial(parallelUpdateJSON, data)
17 pool = Pool()
---> 18 pool.map(parallelUpdateJSON, submatrix)
19 pool.close()
20 pool.join()
/usr/lib/python3.5/multiprocessing/pool.py in map(self, func, iterable, chunksize)
258 in a list that is returned.
259 '''
--> 260 return self._map_async(func, iterable, mapstar, chunksize).get()
261
262 def starmap(self, func, iterable, chunksize=None):
/usr/lib/python3.5/multiprocessing/pool.py in get(self, timeout)
606 return self._value
607 else:
--> 608 raise self._value
609
610 def _set(self, i, obj):
TypeError: string indices must be integers