Pandas 数据框前 ​​x 列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30673684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 23:26:31  来源:igfitidea点击:

Pandas dataframe first x columns

pandasdataframe

提问by ahajib

I have a dataframe with about 500 columns and that's why I am wondering if there is anyway that I could use head() function but want to see the first 50 columns for example.

我有一个包含大约 500 列的数据框,这就是为什么我想知道是否可以使用 head() 函数但想查看前 50 列。

Thanks

谢谢

回答by Ami Tavory

I wasn't sure if you meant rows or columns.

我不确定你是指行还是列。

If it's rows, then

如果是行,那么

df.head(50)

will do the trick.

会做的伎俩。

If it's columns, then

如果是列,那么

df.iloc[:, : 50]

will work.

将工作。

Of course, you can combine them.

当然,您可以将它们组合起来。



You can see this stuff at Indexing and Selecting Data.

您可以在Indexing and Selecting Data 中看到这些内容。