Data in a table can be None or NaN (not a number). Pandas has a function isna
that for each element in the table, is True if the element is missing (None or NaN) or False otherwise.
Consider the table
import pandas as pd df = pd.DataFrame({'count': [np.NaN, 2], 'fruit': ['apple', None]})
count | fruit | |
---|---|---|
1 | np.NaN | apple |
2 | 2 | None |
Task: Write a function, na_rows(df)
which takes in the DataFrame, df
and returns only the rows that have at least one missing (None or NaN) element.
df = pd.DataFrame({'count': [np.NaN, 2, 3], 'fruit': ['apple', None, 'orange']})
count | fruit | |
---|---|---|
0 | nan | apple |
1 | 2 | |
2 | 3 | orange |
count | fruit | |
---|---|---|
0 | nan | apple |
1 | 2 |