Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有办法检查数据帧中的尾列?_Python_Pandas - Fatal编程技术网

Python 有没有办法检查数据帧中的尾列?

Python 有没有办法检查数据帧中的尾列?,python,pandas,Python,Pandas,我希望在数据框中看到一些列,但从列的尾部看。不是排 通常,当您想要检查数据帧时,以下是最简单的方法 print(df.head(5)) Au Ag Al As ... Zn Zr SAMPLE Alt 0 -0.657577 -1.154902 -0.638272 1.541579 ... 0.477121 0.462398 GH101 phy 1 -2.

我希望在数据框中看到一些列,但从列的尾部看。不是排

通常,当您想要检查数据帧时,以下是最简单的方法

print(df.head(5))

             Au        Ag        Al        As  ...        Zn        Zr  SAMPLE    Alt
    0 -0.657577 -1.154902 -0.638272  1.541579  ...  0.477121  0.462398   GH101    phy
    1 -2.431798  0.149219 -0.537602  1.086360  ...  1.681241 -0.301030   GH102  ad-ag
    2 -2.568636  0.178977 -0.346787  1.025306  ...  1.681241 -0.154902   GH103  ad-ag
    3 -2.455932  0.722634 -0.568636  1.378398  ...  1.113943 -0.301030   GH104  ad-ag
    4 -3.698970 -1.522879 -0.292430  1.045323  ...  1.556303 -0.154902   GH105    phy
但是,我想检查这个打印结果右侧的列(从“Alt”到“leftwards”),例如检查5列


还有其他方法吗?

您可以为此使用
iloc
,它允许对数据帧进行基于整数的索引。它采用语法
[i,j]
,其中
i
索引行和
j
索引列,并允许切片。(文件)

在本例中,您需要所有行和最后五列,因此可以执行以下操作:

df.iloc[:, -5:]

您可以为此使用
iloc
,它允许对数据帧进行基于整数的索引。它采用语法
[i,j]
,其中
i
索引行和
j
索引列,并允许切片。(文件)

在本例中,您需要所有行和最后五列,因此可以执行以下操作:

df.iloc[:, -5:]
你可以做:

df[df.columns[-5:]]
df.iloc[-5:]
或:

选择最后五个元素(列)

对于行,您可以执行以下操作:

df[df.columns[-5:]]
df.iloc[-5:]
你可以做:

df[df.columns[-5:]]
df.iloc[-5:]
或:

选择最后五个元素(列)

对于行,您可以执行以下操作:

df[df.columns[-5:]]
df.iloc[-5:]

可能是
df[df.columns[-5:]
?很抱歉重复。看来我搜索的方式不够好。我也没有意识到我可以使用iloc来向后选择列。谢谢你让我知道。也许
df[df.columns[-5:]
?很抱歉重复。看来我搜索的方式不够好。我也没有意识到我可以使用iloc来向后选择列。感谢您让我知道。这相当于
df.tail(5)
,并选择最后5行。OP需要最后5列。这相当于
df.tail(5)
,并选择最后5行。OP想要最后5列。