无法检测数据帧(python)中的NaN值

2024-09-28 21:42:38 发布

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

我从osmnx获得了一个geodataframe:

cities = ox.geocode_to_gdf(['Município de Lisboa', 'Município de Oeiras', 'Município da Amadora', 'Município de Loures', 'Município de Odivelas'])
whole_polygon = cities.unary_union #unary union of both geometries
G = ox.graph_from_polygon(whole_polygon, network_type='drive', simplify=True)
G_nx = nx.relabel.convert_node_labels_to_integers(G)

nodes, edges = ox.graph_to_gdfs(G_nx, nodes=True, edges =  True)

enter image description here

我试图确定name列的值何时为NaN,但由于某些原因,它无法检测到:

for i in range(len(edges)):

    if edges['name'].iloc[i] == float('nan'):
        print('here')

我尝试了float('NaN')而不是代码中的内容。我检查了当name值为NaN时,变量实际上是一个浮点。名称列中有三种类型的值:liststrfloat,其中只有当值为NaN时才使用浮点数


Tags: tonametruedenanfloatoxnx