我有以下熊猫DataFrame df
:
Col1 Col2
0 NaN Type1
1 NaN Type2
2 NaN Type1
3 A Type1
4 NaN Type1
我需要获取Col1
等于NaN
且Col2
等于Type1
的行的索引。这是我尝试过的:
ix = df.eval("Col1.isna() and Col2== 'Type1'")
但这给了我以下错误:
TypeError: unhashable type: 'numpy.ndarray'
答案 0 :(得分:1)
执行以下操作:
df.index[df['Col1'].isna() & df['Col2'].eq('Type1')].tolist()
这应该可行,只是能够运行它。
答案 1 :(得分:0)
尝试一下:
df.loc[(df['Col1'].isna())&(df['Col2'].eq('Type1'))]