我使用python2.7.3和Pandas版本0.12.0。
我希望删除带有NaN索引的行,以便只有有效的site_id值。
print df.head()
special_name
site_id
NaN Banana
OMG Apple
df.drop(df.index[0])
TypeError: 'NoneType' object is not iterable如果我试着放弃一个范围,就像这样:
df.drop(df.index[0:1])我知道这个错误:
AttributeError: 'DataFrame' object has no attribute 'special_name'发布于 2015-11-26 12:47:13
对于熊猫版本>= 0.20.0,您可以:
df = df[df.index.notnull()]旧版本:
df = df[pandas.notnull(df.index)]要把它分解:
notnull生成一个布尔掩码,例如[False, False, True],其中True表示对应位置为null的值(numpy.nan或None)。然后使用df[boolean_mask]选择其索引与掩码中的真值相对应的行。
https://stackoverflow.com/questions/19670904
复制相似问题