获取带有空日期的行 pandas python [英] get rows with empty dates pandas python
本文介绍了获取带有空日期的行 pandas python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看起来像这样:
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
我想过滤掉空的 Dates 行并将其保存在数据框 blankDate 中:
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?
推荐答案
一种方法是用 nan 替换空单元格,然后使用 isnull()
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()]
这篇关于获取带有空日期的行 pandas python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文