Reputation: 6485
I have a Pandas dataframe which has a column date_closed
of type datetime64[ns]
. When I find the unique values there are some NaT there. How can I only filter the rows whose date_closed in not NaT
df['date_closes'].unique()
btw, what does NaT means? is it Null? When I value_counts() , the NaT's does not appear! Why?
df['date_closed'].value_counts()
Upvotes: 2
Views: 1227
Reputation: 294508
Th null value NaT
means not a time just like NaN
means not a number.
Use dropna
df.dropna(subset=[“date_closed”])
Upvotes: 0
Reputation: 48417
For datetime64[ns]
types, NaT represents missing
values. This is a pseudo-native sentinel value that can be represented by numpy in a singular dtype (datetime64[ns]). pandas objects provide intercompatibility between NaT and NaN.
You can read more about handling missing data here : https://pandas.pydata.org/pandas-docs/stable/missing_data.html
For filtering, you can use notnull
method.
df['date_closed'] = df[df.date_closed.notnull()]
Upvotes: 2