Home > other >  Getting typerror: bad operand for unary ~: 'Timestamp'
Getting typerror: bad operand for unary ~: 'Timestamp'

Time:05-29

I have a dataframe in a dataframe for my source data. I am trying to sort the internal dataframe for max on date and then take the inverse of that for the remaining rows. Here's a sample of the code:

for cdf in dfile:
    if caseid == 'curr':
        df = dfile[cdf]['Date'].max() #this returns the correct value
        dfile = dfile[~df]

I'm getting the typeError: bad operand type for unary ~: 'Timestamp'

What am I missing in the inverse mask/filter?

CodePudding user response:

You cann't use ~ to Timestamp object, you can try boolean masking

        dfile = dfile[dfile['Date'] != df]
  • Related