Skip to content
Advertisement

How to select values from one column in function of the values of multiple other columns

Here is the original data:

JavaScript

I would like to be able to get the value of Year in function of the values of Name and Wine. It would return all the values in the Year column of the entries that have the corresponding values in the Name and Wine columns.

For example: with the key ['Mark', 'Volnay'] I would get the values [1983, 1979]

I tried manipulating the data and here is the best I could get.

Keep one instance of each key:

JavaScript

Remove the Year column

JavaScript

Get the values in a list

JavaScript

I now have the keys I need, but I can’t get the values in the original dataframe in function of the value of the key.

Advertisement

Answer

You can also use groupby with get_group

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement