df.loc[df.variable[mask].diff() == 1] 但是当我写它的时候,它返回一个奇怪的错误 IndexingError: Unalignable boolean Seriesprovided as indexer (index of the boolean Series and of the indexed object do not match). variable是一系列布尔值,而mask只是一个如下所示的间隔: mask = df.time_var.dt.date == datetime.d