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

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]?



Solution 1:[1]

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]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 richardec