Reputation: 3173
it looks like this:
Dates N-D unit
0 1/1/2016 Q1 UD
1 Q2 UD
2 Q3 UD
3 2/1/2016 Q4 UD
4 5/1/2016 Q5 UD
5 Q6 UD
I want to filter out the empty Dates rows and save it in a dataframe blankDate:
Dates N-D unit
1 Q2 UD
2 Q3 UD
5 Q6 UD
blankDate=df1[df1['Dates']== ''] #this didn't work
df1['Discharge Date'] = pd.to_datetime(df1['Discharge Date']) #then I converted the column to date format but still doesn't work
if the column is a string this piece of code works, it also works on numbers I think
blankDate=df1[df1['stringcolumn']== '']
but how do I compare to empty date rows?
Upvotes: 7
Views: 12385
Reputation: 294508
Blanks resolve to False
when cast as Boolean
df[~df.Dates.astype(bool)]
Upvotes: 1
Reputation: 19957
#use pd.isnull to check nans for date type.
df[pd.isnull(pd.to_datetime(df.Dates))]
Out[1512]:
Dates N-D unit
1 Q2 UD
2 Q3 UD
5 Q6 UD
Upvotes: 4
Reputation: 38415
One way would be to replace empty cells by nan and then use isnull()
df.Dates = df.Dates.replace('', np.nan)
blankDate = df[df.Dates.isnull()]
Upvotes: 7