1

I have two DataFrames: A and B. A comtains two columns: Number and Letter, B also contains two columns: Number1 and Number2, and Number contains same data as in both Number1 and Number2. How can I make a ned dataframe which will have column which contains Number1, Number2 and column with its Letter?

 A
Number Letter
1        e
2        l
3        o
4        s
5        p
6        w 
7        r
8        i
9        u

B
Number1 Number2
1           7
4           9
2           1

Needed output (without dublicats):

Number Letter
    1     e
    4     s
    2     l
    7     r
    9     u

If there was only one column in B, i would make it with "merge", but how to be here? Can anybody help?

1 Answer 1

2

you can use stack() in conjunction with isin():

In [109]: A[A['Number'].isin(B.stack())]
Out[109]:
   Number Letter
0       1      e
1       2      l
3       4      s
6       7      r
8       9      u
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.