Home > OS >  Why do colons not work in pandas iloc if slicing on the basis of both rows & columns
Why do colons not work in pandas iloc if slicing on the basis of both rows & columns

Time:03-21

df.iloc[[1,4], [1,6]] works, but what if I want rows [1:4] inclusive, and columns [1:6] inclusive?

I know I can list the rows/columns that I want eg df.iloc[[1,2,3,4],[1,2,3,4,5,6]]

but what if the quantity of rows/columns makes this impractical, say, it was [7:50]?

CodePudding user response:

df.iloc[[1,2,3,4],[1,2,3,4,5,6]] is equivalent to df.iloc[1:5, 1:7], or df.iloc[1:4 1, 1:6 1]

  • Related