Getting "AttributeError: 'numpy.ndarray' object has no attribute 'transform'" from esda.Moran

910 views Asked by At

Trying to get Moran's I. A test but getting "AttributeError: 'numpy.ndarray' object has no attribute 'transform'" because of the last line of code. Both of the variables are arrays and they look like this:

0       1024.798431
1        859.662720
2        870.632530
3        819.316065
4        930.600992
           ...     
5567     842.415062
5568     991.513211
5569     908.701993
5570     909.431369
5571     644.946254
Name: Auxilio, Length: 5572, dtype: float64

peso_espacial:

array([876.56886196, 815.34772578, 871.227145  , ..., 903.74618016,
       880.30363602, 885.61222452])

And the code is this:

mun = geobr.read_municipality(code_muni="all", year=2019)
mun = mun.rename(columns={'code_muni': 'Municipio'})
mun['Municipio'] = mun['Municipio'].astype(int).astype(str).str[:-1].astype(np.int64)
impacto2020 = pd.read_excel(path)
mapa = pd.merge(mun,impacto2020,on='Municipio',how='left')
qW = ps.lib.weights.Queen.from_dataframe(mapa)
qW.transform = 'r'
peso_espacial = lp.weights.lag_spatial(qW, mapa['Auxilio'])
peso_espacial = np.nan_to_num(peso_espacial)
auxilio = mapa['Auxilio']
from esda.moran import Moran
moran = Moran(auxilio, peso_espacial)

Don't know how to fix it, already tried converting it to a Series but it gets pretty much the same AttributeError. And this should return a number between 0 and 1.

Full error traceback:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-63-e8e3103abd6b> in <module>
      1 from esda.moran import Moran
----> 2 moran = Moran(auxilio, peso_espacial)

/opt/anaconda3/lib/python3.8/site-packages/esda/moran.py in __init__(self, y, w, transformation, permutations, two_tailed)
    159         y = np.asarray(y).flatten()
    160         self.y = y
--> 161         w.transform = transformation
    162         self.w = w
    163         self.permutations = permutations

AttributeError: 'numpy.ndarray' object has no attribute 'transform'
0

There are 0 answers