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?

Asdfg
  • 11,362
  • 24
  • 98
  • 175
  • Is it necessary to make dataframe u can also use dictionary help in finding is the row exist or not – Rahim Khalid Jul 10 '17 at 20:07
  • I would like to keep it dataframe as there are many other things I need to do on the ValidationFailedDataFrame – Asdfg Jul 10 '17 at 20:10
  • Possible duplicate of [Pandas select row of data frame by integer index](https://stackoverflow.com/questions/16096627/pandas-select-row-of-data-frame-by-integer-index) – cs95 Jul 10 '17 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()` – Asdfg Jul 10 '17 at 20:14

1 Answers1

1

Got it.

ValidationFailedDataFrame.query('index == 4')

OR

ValidationFailedDataFrame.loc[[4]]
Asdfg
  • 11,362
  • 24
  • 98
  • 175