import pandas as pd
df = pd.DataFrame([[1, 2], [3, 4], [5, 6]])
print(df)
# 0 1
# 0 1 2
# 1 3 4
# 2 5 6
print(df.loc[pd.Series([True, False, True])])
# 0 1
# 0 1 2
# 2 5 6
print(df.loc[pd.Series([True, False])])
# Traceback (most recent call last):
# pandas.core.indexing.IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).
df.variable[mask].diff() == 1
- это логическая серия, длина которой отличается от длины df
, поэтому pandas не может решить, какие строки выбрать. Вероятно, вы можете использовать это:
df.loc[(df.variable[mask].diff() == 1).index]