How to get a value of a column based on the id's given from another table
1
I wanted to extract the value of a column given another column with id's of a different dataset. DF-1: ID A B 1 cat 22 2 dog 33 3 mamal 44 4 rat 55 5 rabbit 66 6 puppy 77 DF-2: name fav_animal x 1,2,3 y 2,3 z 3,4 I wanted to see the fav animals of x in a new list say name_animal. code: #storing all the id's of x frist list_id = name_animal = for i in list_ids: name_animal.append(df1.loc[df1.id == i, 'A'].values.to_list() Output: list_id = [1,2,3] name_animal = ['cat','dog','mamal']
python python-3.x pandas
share | improve this question
a...