0

I have two dataframes with equal number of rows.

df_a:

index   Id   X   Y
1       10   x1  - 
2       20   x2  -

-----------

df_b:

index   PostId   Text   
3       10       abcd
4       20       efg

Now how can I transform values of df_b['Text'] to df_a['Y']. resulting this:

df_a:

index   Id   X   Y
1       10   x1  abcd
2       20   x2  efg

Note that indexes of mentioned dataframes are not the same.

0

1 Answer 1

1

Because of the same number of rows, you can assign numpy array:

df_a['Y'] = df_b['Text'].to_numpy()

Older pandas versions:

df_a['Y'] = df_b['Text'].values

If want to map or merge be free to use some of solution from this answer.

Sign up to request clarification or add additional context in comments.

9 Comments

this is trivial
@jezrael there is a warning happening: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead
@AliKhatami - How is created df_a and df_b ?
@AliKhatami - Maybe is necessary copy like explained here or here
|

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.