Skip to content

Getting an error while trying to calculate knn weights from dataframe #441

@revanthApricelabs

Description

@revanthApricelabs

Hey .Im using python 3.8.10,pysal 2.5,scipy 1.7.1,numpy 1.20.0 on wsl2 in windows 11.
I am getting the following error while trying to compute knn weights :

ValueError                                Traceback (most recent call last)
/tmp/ipykernel_177/221878346.py in <module>
----> 1 w = weights.KNN.from_dataframe(geo_df, k=50,distance_metric='arc',radius = 6378.1)
      2 w.transform = 'R'

~/.local/lib/python3.8/site-packages/libpysal/weights/distance.py in from_dataframe(cls, df, geom_col, ids, *args, **kwargs)
    277         elif isinstance(ids, str):
    278             ids = df[ids].tolist()
--> 279         return cls(pts, *args, ids=ids, **kwargs)
    280 
    281     def reweight(self, k=None, p=None, new_data=None, new_ids=None, inplace=True):

~/.local/lib/python3.8/site-packages/libpysal/weights/distance.py in __init__(self, data, k, p, ids, radius, distance_metric, **kwargs)
    121         for i, row in enumerate(to_weight):
    122             row = row.tolist()
--> 123             row.remove(i)
    124             row = [ids[j] for j in row]
    125             focal = ids[i]

ValueError: list.remove(x): x not in list

It worked on other datafiles but keeps failing on this particular dataset.
Also the distance_metric for the KNN.from_dataframe function should be 'arc' in the tutorials containing geopandas dataframes
sample_file.csv

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions