close

How to select column and rows in pandas without column or row names?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to select column and rows in pandas without column or row names in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to select column and rows in pandas without column or row names?

  1. How to select column and rows in pandas without column or row names?

    Use iloc. It is explicitly a position based indexer. ix can be both and will get confused if an index is integer based.

  2. select column and rows in pandas without column or row names

    Use iloc. It is explicitly a position based indexer. ix can be both and will get confused if an index is integer based.

Method 1

Use iloc. It is explicitly a position based indexer. ix can be both and will get confused if an index is integer based.

df.iloc[:, [4]]
enter image description here

For all but the fifth column

slc = list(range(df.shape[1]))
slc.remove(4)

df.iloc[:, slc]
enter image description here

or equivalently

df.iloc[:, [i for i in range(df.shape[1]) if i != 4]]

Method 2

If you want the fifth column:

df.ix[:,4]

Stick the colon in there to take all the rows for that column.

To exclude a fifth column you could try:

df.ix[:, (x for x in range(0, len(df.columns)) if x != 4)]

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read