Issue
I have a pandas dataframe that I want to to filter the dataframe using column 'closed_date', which contains dates. I am trying to filter so that either the value is null or the value is a date within the last year.
df = df[(df['closed_date']>dt.today()-td(days=365)) | (df['closed_date'].isnull)]
This filter is what I am trying to get work but fails and gets this error
Exception has occurred: AssertionError unsupported operand type(s) for |: 'bool' and 'method'
When I break it apart and try each aspect on its own, I get the expected results of dates within the last year or null.
Variants I have tried:
df = df[(df['closed_date']>dt.today()-td(days=365)) or (df['closed_date'].isnull)]
Error:
Exception has occurred: ValueError The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
df = df[(df['closed_date']>dt.today()-td(days=365)) or (df['closed_date'].isnull())]
Error:
Exception has occurred: ValueError The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Solution
I think you are missing the parentheses to call the method isnull
. Try:
df = df[(df['closed_date'] > dt.today() - td(days=365)) | (df['closed_date'].isnull())]
Answered By - Zach Flanders
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.