gpt4 book ai didi

python - Pandas 索引困惑

转载 作者:太空宇宙 更新时间:2023-11-04 05:33:20 25 4
gpt4 key购买 nike

在查看 pandas 中的索引时,我遇到了一些应该很简单的问题。如果 df 是一个足够长的 DataFrame,则 df[1:2] 给出第二行,但是,df[1] 给出错误df[[1]] 给出第二列。这是为什么?

最佳答案

使用 df.iloc[1] 选择数据帧的第二行(它使用基于零的索引)。要选择第二列,请使用 df.iloc[:, 1](: 是用于选择所有行的切片符号)。

关于python - Pandas 索引困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36394194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com