1
import pandas as pd df = pd.DataFrame(np.zeros((8, 8)) df.index = [1, 2, 3, 4, 5, 6, 7, 8] df.columns = [1, 2, 3, 4, 5, 6, 7, 8] df[0][0] = "word" 

Now I want to find the position of the string "word",so something like df.function[df == "word"]. And I want the return to be [0, 0] for position

How do I do this?

1 Answer 1

4

You can use np.where:

df = pd.DataFrame(np.zeros((8, 8))) df.index = [1, 2, 3, 4, 5, 6, 7, 8] df.columns = [1, 2, 3, 4, 5, 6, 7, 8] df.iloc[0,0] = "word" 

Find the position with:

i, c =np.where(df == "word") print(df.iloc[i, c]) 1 1 word 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.