如何选择数据框的最后一列 [英] How to select the last column of dataframe

查看:76
本文介绍了如何选择数据框的最后一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在寻找这个问题的答案了,但是我能弄清楚的是:

I have done some searching for the answer to this question, but all I can figure out is this:

df[df.columns[len(df.columns)-1]]

在我看来,这似乎很古怪,不合蟒蛇风(而且很慢?).

which to me seems unweildy, and un-pythonic (and slow?).

在不指定列名称的情况下,为pandas数据框中的最后一列选择数据的最简单方法是什么?

What is the easiest way to select the data for the last column in a pandas dataframe without specifying the name of the column?

推荐答案

使用iloc并针对最后一列(-1)选择所有行(:):

Use iloc and select all rows (:) against the last column (-1):

df.iloc[:,-1]

这篇关于如何选择数据框的最后一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆