当您两次编写该系列的名称时(第二次将其编写)时,为什么索引编号会更改?
我输入此内容:
test2 = [1, 2, 3, 4]
test3 = pd.Series(test2)
print(test3)
print(test3[3])
print(test3[test3[2]])
明白:
0 1
1 2
2 3
3 4
type: int64
4
4
基本上,我正在尝试了解索引编号正在发生的事情。当您两次列出串联名称时,为什么一排有效地被切割,或者索引 - 搜索 - 搜索量转移到了下一个下行? (如在似乎是同一系列唯一值的不同索引编号所证明的那样,但得到相同的答案)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
没有“ cut ”的行,也没有跳至下一个值。索引总是可再现的,您可能会误解其工作原理。
test3 [x]
为您提供值y
,该值由IndiceX
:在
test3 [test3 [2 [2 [2) ]]
,第一个 test3 [2] 被评估。2
在索引中,匹配值为3
。巧合的是,3
作为一个值也在索引中,因此test [test3 [2]]
等于test3 [3]
,并返回4
。如果您的系列是
test3 = pd.Series([[6,7,8,9])
您只会在运行test3 [test3 [2]]
as <的错误中获得错误代码>测试[8] 不存在。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 valuey
that is indexed by the indicex
:In the case of
test3[test3[2]]
, firsttest3[2]
is evaluated.2
is in the index and the matching value is3
. Coincidentally,3
as a value is also in the index, sotest[test3[2]]
is equivalent totest3[3]
and returns4
.If your Series was
test3 = pd.Series([6, 7, 8, 9])
you would just get an error runningtest3[test3[2]]
astest[8]
is inexistent.进行测试时,索引没有变化[x],它在索引x上返回值:
test [test [2]]:
The indexes are not changing when you do test[x] IT return you the value at index x:
test[test[2]]] :