从esda.Moran获取“AttributeError:'numpy.ndarray'对象没有属性'transform'”

2024-05-19 12:03:50 发布

您现在位置:Python中文网/ 问答频道 /正文

试图获取Moran的I.A测试,但由于最后一行代码,获取“AttributeError:'numpy.ndarray'对象没有属性“transform'”。这两个变量都是数组,它们如下所示:

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

西班牙比索:

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

代码是这样的:

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)

不知道如何修复它,已经尝试将它转换为一个系列,但它得到了几乎相同的AttributeError。这应该返回一个介于0和1之间的数字

完全错误回溯:

---------------------------------------------------------------------------
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'

Tags: fromselfnptransformattributeerrormoranastypemapa

热门问题