Getting typerror: bad operand for unary ~: 'Timestamp'

Getting typerror: bad operand for unary ~: 'Timestamp'

我的源数据的数据框中有一个数据框。我正在尝试对最大日期的内部数据框进行排序,然后对剩余的行取反。这是代码示例:

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

我收到类型错误:一元操作数类型错误 ~:'Timestamp'

我在逆mask/filter中遗漏了什么?

你不能使用 ~ 到时间戳对象,你可以尝试布尔掩码

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