0

Assume I have two dataframe with same structure, and I know row 1 in the dfA is also in dfB.

I am wondering how to find the location of row 1 in dfB.

Image dfA

For example, I have a dfA as shown in the graph. If I know there exist a same row3 in dfB. How can I find the location of row3 (age: 53, workclass: Private) in dfB. ( dfA and dfB both has around 40000 rows, and has same number of features.)

Thank you in advance.

Community
  • 1
  • 1
Max
  • 35
  • 5

1 Answers1

0

To get only one row that particular row must be unique or else you'll get more than one rows.

dfB[['age', 'workclass']][(dfA.age == 53) & (dfA.workclass == "Private")]

If you want all columns of the dfB dataframe just remove the [['age', 'workclass']] and you will get all the rows in dfB dataframe where age = 53 and workclass = "Private".

To get the index values of the rows in the second dataframe just add .index at the end.

dfB[['age', 'workclass']][(dfA.age == 53) & (dfA.workclass == "Private")].index
Kranthi Kiran
  • 121
  • 1
  • 6
  • Thank you Kranthi. Is there a faster way, each row actually has 14 features...I just want to get the location of the same row in the second dataframe. – Max Jun 16 '18 at 05:17
  • I dont think there is a faster way than this. And btw by location you meant index in the second dataframe? If you meant that I've updated my answer. Please dont hesitate to upvote! :) @ShihaoWen – Kranthi Kiran Jun 16 '18 at 05:59