i'm trying to do spatial lag with a dataset but i don't understand what i need to change to satisfy this type error? i can't figure out what it is referring to, as i thought initially it was because the 'ptal' column was a float, so i changed it to be an integer, but it came up with the same error, so it can't be this that the error is referring to.
any suggestions?
ptal_lsoas[['ptal']]=ptal_lsoas[['ptal']].astype('float64')
ptal_lsoas.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 4835 entries, 0 to 4834
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 geometry 4835 non-null geometry
1 lsoa11cd 4835 non-null object
2 avptai2015 4835 non-null float64
3 ptal 4835 non-null float64
4 ptaihigh 4835 non-null float64
5 ptailow 4835 non-null float64
dtypes: float64(4), geometry(1), object(1)
memory usage: 264.4+ KB
pr = ps.viz.mapclassify.Quantiles(gdf['ptal'], k=5)
f, ax = plt.subplots(1, figsize=(20, 12))
gdf.assign(cl_pr=pr.yb).plot(column='cl_pr', categorical=True, k=5, cmap='OrRd',
linewidth=0.1, ax=ax, edgecolor='white', legend=True)
plt.title('ptal spatial lag')
plt.show()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-185-750b023d96cc> in <module>
----> 1 pr = ps.viz.mapclassify.Quantiles(gdf['ptal'], k=5)
2 f, ax = plt.subplots(1, figsize=(20, 12))
3 gdf.assign(cl_pr=pr.yb).plot(column='cl_pr', categorical=True, k=5, cmap='OrRd',
4 linewidth=0.1, ax=ax, edgecolor='white', legend=True)
5
/opt/conda/lib/python3.8/site-packages/mapclassify/classifiers.py in __init__(self, y, k)
1458 def __init__(self, y, k=K):
1459 self.k = k
-> 1460 MapClassifier.__init__(self, y)
1461 self.name = "Quantiles"
1462
/opt/conda/lib/python3.8/site-packages/mapclassify/classifiers.py in __init__(self, y)
615 self.fmt = FMT
616 self.y = y
--> 617 self._classify()
618 self._summary()
619
/opt/conda/lib/python3.8/site-packages/mapclassify/classifiers.py in _classify(self)
634
635 def _classify(self):
--> 636 self._set_bins()
637 self.yb, self.counts = bin1d(self.y, self.bins)
638
/opt/conda/lib/python3.8/site-packages/mapclassify/classifiers.py in _set_bins(self)
1464 y = self.y
1465 k = self.k
-> 1466 self.bins = quantile(y, k=k)
1467
1468
/opt/conda/lib/python3.8/site-packages/mapclassify/classifiers.py in quantile(y, k)
232 if p[-1] > 100.0:
233 p[-1] = 100.0
--> 234 q = np.array([stats.scoreatpercentile(y, pct) for pct in p])
235 q = np.unique(q)
236 k_q = len(q)
/opt/conda/lib/python3.8/site-packages/mapclassify/classifiers.py in <listcomp>(.0)
232 if p[-1] > 100.0:
233 p[-1] = 100.0
--> 234 q = np.array([stats.scoreatpercentile(y, pct) for pct in p])
235 q = np.unique(q)
236 k_q = len(q)
/opt/conda/lib/python3.8/site-packages/scipy/stats/stats.py in scoreatpercentile(a, per, limit, interpolation_method, axis)
1827 axis = 0
1828
-> 1829 return _compute_qth_percentile(sorted_, per, interpolation_method, axis)
1830
1831
/opt/conda/lib/python3.8/site-packages/scipy/stats/stats.py in _compute_qth_percentile(sorted_, per, interpolation_method, axis)
1871
1872 # Use np.add.reduce (== np.sum but a little faster) to coerce data type
-> 1873 return np.add.reduce(sorted_[tuple(indexer)] * weights, axis=axis) / sumval
1874
1875
TypeError: can't multiply sequence by non-int of type 'float'
thanks in advance