Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading