alim1990
alim1990

Reputation: 4972

Python get the index of search within data frame and not an array with type of index

I need to get the value of the index and not an array following a criteria:

quarterValue = 20
indexOf = df[df["Quarter"]==quarterValue].index

The returning value is:

Int64Index([34], dtype='int64')

What I need is only:

34

Upvotes: 0

Views: 30

Answers (1)

jezrael
jezrael

Reputation: 863301

Select first value by indexing:

idx = indexOf[0]

If possible sometimes is returned empty index solution failed, need trick with next and iter for first value with possible add default if no match:

idx = next(iter(indexOf), 'no value')

Upvotes: 1

Related Questions