0

I have a Pandas DataFrame with 30 columns. I want to filter it to columns and reorder the filtered columns to get: 3rd, 2nd, and columns from 10th to 20th index. Something like this (but this doesn't work):

df.iloc[:, [2, 1, [9:20]]]

I assume that the problem is that I try to mix direct indices and ranges with iloc.

And how to achieve the same goal with explicit column names (assuming the correct column name strings):

df[["col_2", "col_1", ["col_9":"col_20"]]]
Fredrik
  • 411
  • 1
  • 3
  • 14

0 Answers0