1

I have a dataframe with 5 rows on which I am doing some validations. If the row does not pass validation, I am adding it to a second dataframe named ValidationFailedDataFrame.

It is OK for the first validation but for the second validation, I want to check if the particular row is already added to the ValidationFailedDataFrame or not and if it is, I want to grab that row and append the error message.

This is how my ValidationFailedDataFrame looks like:

enter image description here

As you can see in the picture, the row that failed the validation was 4th row in the original DataFrame.

How do I query ValidationFailedDataFrame saying give me 4th row of Original DataFrame if you have?

4
  • Is it necessary to make dataframe u can also use dictionary help in finding is the row exist or not Commented Jul 10, 2017 at 20:07
  • I would like to keep it dataframe as there are many other things I need to do on the ValidationFailedDataFrame Commented Jul 10, 2017 at 20:10
  • Possible duplicate of Pandas select row of data frame by integer index Commented Jul 10, 2017 at 20:12
  • df.iloc[3].tolist() gives me out-of-bound error as there is only one row in the dataframe. df.iloc[0].tolist() works but I would like to access it with df.iloc[4].tolist() Commented Jul 10, 2017 at 20:14

1 Answer 1

1

Got it.

ValidationFailedDataFrame.query('index == 4')

OR

ValidationFailedDataFrame.loc[[4]]
Sign up to request clarification or add additional context in comments.

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.