2

I have the following two dataframes:

near0   near1   near2
SCSCO   LFLAF   GOMAN
VDJUL   MEIRA   L3N05
LOSEN   AMCLF   PIRF2
AOSSF   MEPRI   FLLCA

and

  key   vlaue
SCSCO   _1234
VDJUL   _4321
PIRF2   _5677

How can I replace (or add a new column) such that either

near0   near1   near2
_1234   LFLAF   GOMAN
_4321   MEIRA   L3N05
LOSEN   AMCLF   _5677
AOSSF   MEPRI   FLLCA

or

near0   near1   near2   near0_f   near1_f   near2_f
SCSCO   LFLAF   GOMAN     _1234     LFLAF     GOMAN
VDJUL   MEIRA   L3N05     _4321     MEIRA     L3N05
LOSEN   AMCLF   PIRF2     LOSEN     AMCLF     _5677
AOSSF   MEPRI   FLLCA     AOSSF     MEPRI     FLLCA

hold?

1 Answer 1

3

You can do replace pass series

newdf1=df1.replace(df2.set_index('key').vlaue)
   near0  near1  near2
0  _1234  LFLAF  GOMAN
1  _4321  MEIRA  L3N05
2  LOSEN  AMCLF  _5677
3  AOSSF  MEPRI  FLLCA
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.