当您两次编写该系列的名称时(第二次将其编写)时,为什么索引编号会更改?

发布于 2025-02-10 15:43:45 字数 327 浏览 1 评论 0原文

我输入此内容:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放手` 2025-02-17 15:43:45

没有“ cut ”的行,也没有跳至下一个值。索引总是可再现的,您可能会误解其工作原理。

test3 [x]为您提供值y,该值由Indice X

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 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.

删除→记忆 2025-02-17 15:43:45

进行测试时,索引没有变化[x],它在索引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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文