Hello,
Maybe something like df.iloc[:, [0, 2, 5, 6, 7, 8, 9]]
. Based on the info you gave, I presume columns 6 to 10 refers to the sixth to tenth column, and not column indexed by 6 to column indexed by 10.
If you want to use slice for 6:11
, you’ll need something a bit more complicated as mentioned here. One (less elegant) option is df.iloc[:, [0, 2] + list(range(5,10))]
, and you can find other methods in the previous link.
Similar to the above, df.iloc[[1, 4, 6, 14, 15, 16, 17, 18, 19]
Or df.iloc[[1, 4, 6] + list(range(14,20))]
.
Maybe numpy.r_
(doc) would be better.
# select all rows, and first, third, and sixth to tenth columns
df.iloc[:, np.r_[0, 2, 5:10]]
# select all columns, and second, fifth, seventh, and fifteenth to twentieth rows
df.iloc[np.r_[1, 4, 6, 14:20]]