I am working with a DataFrame
which looks like this
List Numb Name
1 1 one
1 2 two
2 3 three
4 4 four
3 5 five
and I am trying to compute the following output.
List Numb Name
one 1 one
one 2 two
two 3 three
four 4 four
three 5 five
In my current approach I'm trying to iterate through the columns, then replace values with the contents of a third column.
For example, if List[0][1]
is equal to Numb[1][1]
replace column List[0][1]
with 'one'
.
How could I make an iteration like this work, or alternatively solve the problem without explicitly iterating at all?
Use map
df['List'] = df['List'].map(df.set_index('Numb')['Name'])
List Numb Name
0 one 1 one
1 one 2 two
2 two 3 three
3 four 4 four
4 three 5 five
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With