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.
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.