How can I select the rows with null values in respect of columns name?
What I have:
ID | A | B |
---|---|---|
1 | a | b |
2 | v | |
3 | y | |
4 | w | j |
5 | w |
What I want:
Select rows with null in respect with e.g. column B
:
ID | B |
---|---|
3 | y |
5 | w |
Use pandas.DataFrame.pop
and pandas.Series.isna
:
>>> df
ID A B
0 1 a b
1 2 NaN v
2 3 y NaN
3 4 w j
4 5 w NaN
>>> df[df.pop('B').isna()]
ID A
2 3 y
4 5 w
Use pop
if you do not need column 'B'
in the original dataframe afterwards. Otherwise, use pandas.DataFrame.drop
:
>>> df[df['B'].isna()].drop('B', axis=1)
I guess you can use isna() or isnull() functions.
df[df['column name'].isna()]
(or)
df[df['column name'].isnull()]
B
!df[df['B'].isna()]