0

I am using Python 3.7. I am working on Titanic survival prediction ML project. The CSV file have "age" column, that has some null values in it. So I want to train my model in two sets - 1. train set having age column with some valid values; 2. train set for the rows which have null value in age column.

I have the 1st train set. How can I acquire all those rows with null values in "age" column?

1 Answers1

0

You can filter by using the methods isnull or notnull from pandas.Series.

>>> df = pd.DataFrame({"age": [1, 2, None, 3, 4], "name": ["a", "b", "c", "d", "e"]})
>>> df[ df.age.isnull() ]
   age name
2  NaN    c
>>> df[ df.age.notnull() ]
   age name
0  1.0    a
1  2.0    b
3  3.0    d
4  4.0    e
MkWTF
  • 1,372
  • 7
  • 11