Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get rows with empty dates pandas python

Tags:

python

pandas

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?

like image 873
Jessica Avatar asked May 22 '17 23:05

Jessica


1 Answers

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()]
like image 152
Vaishali Avatar answered Oct 10 '22 16:10

Vaishali