I enter this:
test2 = [1, 2, 3, 4]
test3 = pd.Series(test2)
print(test3)
print(test3[3])
print(test3[test3[2]])
And get this:
0 1
1 2
2 3
3 4
type: int64
4
4
Basically I'm trying to understand what's happening to the index numbering. Why does a row effectively get cut, or is the index-search-result moved to the next lower row, when you list the series name twice? (as evidenced by selecting different index numbers on what appears to be the same series of unique values, but getting the same answer)
CodePudding user response:
The indexes are not changing when you do test[x] IT return you the value at index x:
test[3]= the value at index 3 =4
test[test[2]]] :
1- test[2] = the value at index 2 =3
2- test[test[2]] = test[3] = the value at index 3 = 4
CodePudding user response:
There is no row that is "cut", nor jump to a next value. Indexing is always reproducible, you might misunderstand how it is working.
test3[x]
gives you the value y
that is indexed by the indice x
:
In the case of test3[test3[2]]
, first test3[2]
is evaluated. 2
is in the index and the matching value is 3
. Coincidentally, 3
as a value is also in the index, so test[test3[2]]
is equivalent to test3[3]
and returns 4
.
If your Series was test3 = pd.Series([6, 7, 8, 9])
you would just get an error running test3[test3[2]]
as test[8]
is inexistent.