Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas dataframe first x columns [duplicate]

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.

Thanks

like image 396
ahajib Avatar asked Jun 05 '15 18:06

ahajib


People also ask

How can I find duplicate columns in pandas?

To find duplicate columns we need to iterate through all columns of a DataFrame and for each and every column it will search if any other column exists in DataFrame with the same contents already. If yes then that column name will be stored in the duplicate column set.

How do I get rid of duplicate columns in pandas?

To drop duplicate columns from pandas DataFrame use df. T. drop_duplicates(). T , this removes all columns that have the same data regardless of column names.

What is Loc and ILOC?

loc[] is used to select rows and columns by Names/Labels. iloc[] is used to select rows and columns by Integer Index/Position. zero based index position.


1 Answers

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.

like image 192
Ami Tavory Avatar answered Sep 19 '22 04:09

Ami Tavory