3

I have the following Pandas DataFrame:

                             A                                        B
0                     Exporter                       Invoice No. & Date
1                 ABC PVT LTD.        ABC/1234/2022-23 DATED 20/08/2022
2                 1234/B, XYZ,
3           ABCD, DELHI, INDIA               Proforma Invoice No. Date.
4                                    AB/CDE/FGH/2022-23/1234 20.08.2022
5                    Consignee          Buyer (If other than consignee)
6                      ABC Co.
8            P.O BOX NO. 54321
9              Berlin, Germany

Now I want to search for a value in this DataFrame, and store the index and column name in 2 different variables.

For example:
If I search "Consignee", I should get

index = 5
column = 'A'
0

1 Answer 1

5

Assuming you really want the index/column of the match, you can use a mask and stack:

df.where(df.eq('Consignee')).stack()

output:

5  A    Consignee
dtype: object

As list:

df.where(df.eq('Consignee')).stack().index.tolist()

output: [(5, 'A')]

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I will get index and column name using result[0][0] and result[0][1].

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.