lsheng
lsheng

Reputation: 3729

select multiple columns in pandas data frame with column index as sequential number

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

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?

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.

Thanks in advance.

Upvotes: 9

Views: 9249

Answers (1)

lsheng
lsheng

Reputation: 3729

Looks that I found it....

By using iloc..

df.iloc[:,your_col_index]

Upvotes: 14

Related Questions