1
In [60]: print(row.index)
Int64Index([15], dtype='int64')

I already know that the row number is 15, in this example. But I don't need to know it's type or anything else. The variable which stores it would do something based on what that number is.

There was something else about pandas I was wondering about. Suppose that this only returns one row:

row = df[df['username'] == "unique name"]  

Is it any less proper to use methods like loc, iloc, etc? They still work and everything, but I was curious if it would still be done this way in larger projects.. Are there preferred methods if it's just one row, as opposed to a list of rows.

thinkvitamin
  • 81
  • 1
  • 12
  • 1
    If you want to access the scalar, use `row.index[0]` assuming row is a single row. For boolean indexing, see unutbu's answer to [Why use loc](http://stackoverflow.com/q/38886080/2285236) – ayhan Sep 02 '16 at 07:31

1 Answers1

1

If you write

row.index[0]

then you will get, in your case, the integer 15.


Note that if you check

dir(pd.Int64Index)

You can see that it includes the list-like method __getitem__.

Ami Tavory
  • 74,578
  • 11
  • 141
  • 185