0
votes

I have a dataframe like. data1 = ID A B C D O T1 1 3 3 2 1 T2 2 4 2 3 0 T3 4 1 1 4 0 T4 5 2 4 5 0 T5 3 5 5 1 1

And other data is.

data2 =

bin A B C D 1 0.2 0.1 0.3 0.4 2 0.1 0.3 0.7 0.9 3 0.5 0.7 0.8 1.0 4 0.15 0.25 0.91 0.71 5 0.35 0.05 0.71 0.58

I want to replace the columns A,B,C,D values in data1 with the bin values in data2, so that the final data looks like below.

data1_updated =

ID A B C D O T1 0.2 0.7 0.8 0.9 1 T2 0.1 0.25 0.7 1.0 0 T3 0.15 0.1 0.3 0.71 0 T4 0.35 0.2 0.91 0.58 0 T5 0.5 0.5 0.71 0.4 1

How to do this??

1

1 Answers

0
votes

You can do column update like this:

>>> data1[['A', 'B', 'C', 'D']] = data2[['A', 'B', 'C', 'D']]
>>> data1
   ID     A     B     C     D  O
0  T1  0.20  0.10  0.30  0.40  1
1  T2  0.10  0.30  0.70  0.90  0
2  T3  0.50  0.70  0.80  1.00  0
3  T4  0.15  0.25  0.91  0.71  0
4  T5  0.35  0.05  0.71  0.58  1