The easier is add [0] - select first value of list with one element:

dfb = df[df['A']==5].index.values.astype(int)[0]
dfbb = df[df['A']==8].index.values.astype(int)[0]

dfb = int(df[df['A']==5].index[0])
dfbb = int(df[df['A']==8].index[0])

But if possible some values not match, error is raised, because first value not exist.

Solution is use next with iter for get default parameetr if values not matched:

dfb = next(iter(df[df['A']==5].index), 'no match')
print (dfb)
4

dfb = next(iter(df[df['A']==50].index), 'no match')
print (dfb)
no match

Then it seems need substract 1:

print (df.loc[dfb:dfbb-1,'B'])
4    0.894525
5    0.978174
6    0.859449
Name: B, dtype: float64

Another solution with boolean indexing or query:

print (df[(df['A'] >= 5) & (df['A'] < 8)])
   A         B
4  5  0.894525
5  6  0.978174
6  7  0.859449

print (df.loc[(df['A'] >= 5) & (df['A'] < 8), 'B'])
4    0.894525
5    0.978174
6    0.859449
Name: B, dtype: float64

print (df.query('A >= 5 and A < 8'))
   A         B
4  5  0.894525
5  6  0.978174
6  7  0.859449
Answer from jezrael on Stack Overflow
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.index.html
pandas.DataFrame.index โ€” pandas 3.0.5 documentation
The index of a DataFrame is a series of labels that identify each row. The labels can be integers, strings, or any other hashable type. The index is used for label-based access and alignment, and can be accessed or modified using this attribute. Returns: pandas.Index ยท
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ user_guide โ€บ indexing.html
Indexing and selecting data โ€” pandas 3.0.6 documentation
In this section, we will focus on the final point: namely, how to slice, dice, and generally get and set subsets of pandas objects. The primary focus will be on Series and DataFrame as they have received more development attention in this area. ... The Python and NumPy indexing operators [] and attribute operator .
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.Index.values.html
pandas.Index.values โ€” pandas 3.0.5 documentation
Index.to_numpy ยท A NumPy array representing the underlying data. Examples ยท For pandas.Index: >>> idx = pd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='int64') >>> idx.values array([1, 2, 3]) For pandas.IntervalIndex: >>> idx = pd.interval_range(start=0, end=5) >>> idx.values <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right] On this page
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ pandas โ€บ pandas-dataframe-index
Pandas Dataframe Index - GeeksforGeeks
March 24, 2026 - One can view the existing index using the .index attribute and later update it based on your requirements. ... import pandas as pd data = {'Name': ['Jake', 'Eve', 'Charlie'], 'Age': [ 22, 35, 28], 'Gender': [ 'Male', 'Female', 'Male'], 'Salary': ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ pandas get index from dataframe
Pandas Get Index from DataFrame - Spark By {Examples}
November 6, 2024 - How to get an index from Pandas DataFrame? DataFrame.index property is used to get the index from the DataFrame. Pandas Index is an immutable sequence
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ how-to-get-the-index-of-a-row-in-a-pandas-dataframe-as-an-integer
How to Get the Index of a Row in a Pandas DataFrame as an Integer | Saturn Cloud Blog
May 1, 2026 - You can pass a single integer or a list of integers to the iloc method to retrieve the corresponding row(s). To get the index of a row as an integer, you can call the index attribute on the resulting DataFrame slice.
Find elsewhere
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.Index.name.html
pandas.Index.name โ€” pandas 3.0.5 documentation
>>> idx = pd.Index([1, 2, 3], name="x") >>> idx Index([1, 2, 3], dtype='int64', name='x') >>> idx.name 'x'
๐ŸŒ
Statology
statology.org โ€บ home โ€บ pandas: get index of rows whose column matches value
Pandas: Get Index of Rows Whose Column Matches Value
July 16, 2021 - This tutorial explains how to get the indices of the rows in a pandas DataFrame whose column matches a certain value.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ pandas โ€บ ref_df_index.asp
Pandas DataFrame index Property
Pandas HOME Pandas Intro Pandas ... Wrong Format Cleaning Wrong Data Removing Duplicates ... The index property returns the index information of the DataFrame....
๐ŸŒ
Towards Data Science
towardsdatascience.com โ€บ home โ€บ latest โ€บ getting the index of rows with certain column value in pandas
Getting the Index of Rows With Certain Column Value in Pandas | Towards Data Science
January 20, 2025 - In today's short guide we discussed how to retrieve the index of rows whose column matches a specified value. Specifically, we showcased how to get the indices using the index property of pandas DataFrames as well as the where() method of NumPy library.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ get-column-index-from-column-name-of-a-given-pandas-dataframe
Get column index from column name of a given Pandas DataFrame - GeeksforGeeks
July 15, 2025 - Index.get_loc() function finds the index of a specified column name and returns an integer if the column name is unique.
๐ŸŒ
Medium
medium.com โ€บ @amit25173 โ€บ how-to-use-pandas-get-row-by-index-b01fa9339cdf
How to Use pandas Get Row by Index? | by Amit Yadav | Medium
April 12, 2025 - Just create a boolean condition and use it to index your DataFrame. What if I want a reverse order of rows? You can reverse the order of rows easily by using slicing. For example: df[::-1] will return the DataFrame in reverse order. Understanding how to use pandas get row by index can significantly improve your data analysis capabilities.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ api โ€บ pandas.DataFrame.sort_index.html
pandas.DataFrame.sort_index โ€” pandas 3.0.5 documentation
If not None, apply the key function to the index values before sorting. This is similar to the key argument in the builtin sorted() function, with the notable difference that this key function should be vectorized. It should expect an Index and return an Index of the same shape.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ docs โ€บ reference โ€บ indexing.html
Index objects โ€” pandas 3.0.5 documentation
Many of these methods or variants thereof are available on the objects that contain an index (Series/DataFrame) and those should most likely be used before calling these methods directly.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-get-rows-index-names-in-pandas-dataframe
How to get rows/index names in Pandas dataframe - GeeksforGeeks
July 11, 2025 - Now, let's print the total count of index. ... # Import pandas package import pandas as pd # making data frame data = pd.read_csv("nba.csv") row_count = 0 # iterating over indices for col in data.index: row_count += 1 # print the row count print(row_count)