在pandas数据框中选择多个列,列索引为序号 [英] select multiple columns in pandas data frame with column index as sequential number

查看:632
本文介绍了在pandas数据框中选择多个列,列索引为序号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试提取数据帧中的第7至第14列。但是

I am trying to extract the 7th to 14th columns in a data frame. However

df [0:3] 仅给出第一行到第三行。

df[0:3] only gives the 1st to 3rd rows.

如果我想找出列,有人知道该怎么办吗?

Does anyone knows what should I do if I want to find out the columns?

我知道如何使用列名,例如 df ['a'] 但由于名称太多,我只想输入类似 df [,7:14] in R。

I know how to do it with column names such as df['a'] but as the names are too many, I just want to type something like df[,7:14] in R.

预先感谢。

推荐答案

看起来我找到了它。...

Looks that I found it....

通过iloc使用。

df.iloc[:,your_col_index]

这篇关于在pandas数据框中选择多个列,列索引为序号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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