Asdfg
Asdfg

Reputation: 12203

pandas - How do I access row in a dataframe by row Index

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?

Upvotes: 1

Views: 4083

Answers (1)

Asdfg
Asdfg

Reputation: 12203

Got it.

ValidationFailedDataFrame.query('index == 4')

OR

ValidationFailedDataFrame.loc[[4]]

Upvotes: 1

Related Questions