How to select rows with NaN in particular column?

656    Asked by EmmaLewis in Devops , Asked on May 10, 2021
Given this dataframe, how to select only those rows that have "Col2" equal to NaN?
In [56]: df = pd.DataFrame([range(3), [0, np.NaN, 0], [0, 0, np.NaN], range(3), range(3)], columns=["Col1", "Col2", "Col3"])
In [57]: df
Out[57]: 
   0   1   2
0  0   1   2
1  0 NaN   0
2  0   0 NaN
3  0   1   2
4  0   1   2
The result should be this one:
Out[57]: 
   0   1   2
1  0 NaN   0

To solve pandas find rows with nan, try the following:

  df[df['Col2'].isnull()]


Your Answer

Interviews

Parent Categories