1
I would like to know how to create a column on a dataframe based on the code of another Python dataframe. For example, I have:
df A:
letra
c
b
d
c
a
df B:
letra codigo
a 10
b 20
c 30
d 40
Expected result is df A to look like this:
letra codigo
c 30
b 20
d 40
c 30
a 10
I didn’t understand why the question was defined as out of scope, but anyway, test using
map
.df['codigo'] = df['letra'].map(df2.set_index('letra')['codigo'])
– Terry