0
Table A :
y  type
1   a
1   a
0   b
1   c
0   b
1   a
------------
Table B
type   x
 a    0.1
 b    0.2
 c    0.3
------------

I want to replace A.type with corresponding x in B. Thus the result I want is:

y  type
1  0.1
1  0.1
0  0.2
1  0.3
Cœur
  • 37,241
  • 25
  • 195
  • 267
Bin
  • 209
  • 1
  • 3
  • 8

1 Answers1

0

Use pd.Series.map

A['type'] = A.type.map(B.set_index('type').x)

    y   type
0   1   0.1
1   1   0.1
2   0   0.2
3   1   0.3
4   0   0.2
5   1   0.1
rafaelc
  • 57,686
  • 15
  • 58
  • 82