Why does pd.Series == int not give exact number int?

In the Data Analysis with Python course in Pandas Series exercise file there is a task: Given the X pandas Series, get numbers equal to 2 or 10

X = pd.Series([-1,2,0,-4,5,6,0,0,-9,10])
X[(X == 2) | (X == 10)]

Out:
1 2
9 10

Seems like per definition of the question you should get number equal exactly 2 or 10,
i.e.: 2, 10.

Is there something special with this boolean query that it gives also the neighboring numbers?

The neighbouring numbers (1, 9) are the default indexes of the series, which are part of data structure of series/array. The query selects the elements of the series which fulfils the condition, and the indexes show the positions of the selected elements in the series. So the output is essentially saying that X[1] and X[9] are the selected elements of the query. They can be useful if you want to do further operations with series sharing the same indexes.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.