无法在数据框中检测到 NaN 值 (python)
Can't detect NaN values in dataframe (python)
我有一个从 osmnx 获得的地理数据框:
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)
我试图确定 name
列的值何时为 NaN
但由于某种原因它无法检测到:
for i in range(len(edges)):
if edges['name'].iloc[i] == float('nan'):
print('here')
我已经尝试 float('NaN')
而不是代码中的内容。我检查了当 name
值为 NaN
时变量确实是一个浮点数。 name栏中的值有3种类型:list
、str
、float
,其中浮点数只有当值为NaN
data = {"h":[1,np.nan,2]}
pd.DataFrame(data).isnull()
#output
h
0 False
1 True
2 False
我有一个从 osmnx 获得的地理数据框:
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)
我试图确定 name
列的值何时为 NaN
但由于某种原因它无法检测到:
for i in range(len(edges)):
if edges['name'].iloc[i] == float('nan'):
print('here')
我已经尝试 float('NaN')
而不是代码中的内容。我检查了当 name
值为 NaN
时变量确实是一个浮点数。 name栏中的值有3种类型:list
、str
、float
,其中浮点数只有当值为NaN
data = {"h":[1,np.nan,2]}
pd.DataFrame(data).isnull()
#output
h
0 False
1 True
2 False