I have a df like this:
a b c 1 NaT w 2 2014-02-01 g 3 NaT x df=df[df.b=='2014-02-01']
will give me
a b c 2 2014-02-01 g
I want a database of all rows with NaT in column b?
df=df[df.b==None] #Doesn't work
I want this:
a b c 1 NaT w 3 NaT x
Using query() to Filter by Column Value in pandas DataFrame. query() function is used to filter rows based on column value in pandas. After applying the expression, it returns a new DataFrame. If you wanted to update the existing DataFrame use inplace=True param.
By using dropna() method you can drop rows with NaN (Not a Number) and None values from pandas DataFrame. Note that by default it returns the copy of the DataFrame after removing rows. If you wanted to remove from the existing DataFrame, you should use inplace=True .
isnull
and notnull
work with NaT
so you can handle them much the same way you handle NaNs
:
>>> df a b c 0 1 NaT w 1 2 2014-02-01 g 2 3 NaT x >>> df.dtypes a int64 b datetime64[ns] c object
just use isnull
to select:
df[df.b.isnull()] a b c 0 1 NaT w 2 3 NaT x
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With