0

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

0

3 Answers 3

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]
Sign up to request clarification or add additional context in comments.

Comments

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 :)

Comments

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.