Skip to content
Advertisement

How to look for specific values and return an index in a dataframe?

I have a DataFrame that looks like this:

JavaScript

So I have a pair of u and v values (the last two columns). So what I want to ask is, if for example I have a value of u = 279 and a value of v = -108, my output would be Index = 2, is there a way to do this?

I tried doing the code below but it only looks for one column only.

JavaScript

As you can see, this method only looks for values within one column (e.g. v column) and may give wrong index values, as you can see, index=1 and index=2 are both v == -108.

To simply put, I want my input to be values from column u and column v as a pair and would give an index value as an output.

Advertisement

Answer

You can use multiple conditions in the expression like this df['u'].eq(279) & df['v'].eq(-108)

JavaScript

Prints:

JavaScript
Advertisement