0

I want to get the numerical position of a particular element of a column

Prince Kumar
  • 23
  • 1
  • 1
  • 3

3 Answers3

1

Use numpy.where with mask only for integer position:

df = pd.DataFrame({'a':[1,2,3]}, index=list('ABC'))

i = np.where(df['a'].eq(2))[0]
print (i)
[1]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
0

I think you can find your answer in here: Python Pandas: Get index of rows which column matches certain value

Also, if you want to get your answer using Openpyxl, you can use the following:

for row in ws.iter_rows():
    for cell in row:
        if cell.value == "test123":
            print(cell.row) //Prints row '1'
            print(cell.column) //Prints column '2'
            print(cell.coordinate) //Prints coordinate 'A5'


Or you can store the values from cell.column/cell.row in a variable and use it later.

Hope that helps :)

Raccoon_17
  • 153
  • 2
  • 15
0

Try this below :

For eg:

import pandas as pd

df = pd.DataFrame({'date':['10/2/2011', '11/2/2011', '12/2/2011', '13/2/2011'], 
                   'product':['p1', 'p2', 'p3', 'p4'], 
                   'latest_price':[1200, 1500, 1600, 352], 
                   'new_price':[1250, 1450, 1550, 400], 
                   'Discount':[10, 10, 10, 10]}, index=['0', '1', '2', '3']) 


print(df) 


index = df[df['new_price']<500].index        # --------> Here you can give any condition to get your index.

print(index)
Abhishek Kulkarni
  • 1,747
  • 1
  • 6
  • 8