Pandas – get “these” based on “those”

Here is a common scenario for me: I have 2 related dataframes, and I want to select only the values from the one dataframe based on criteria from the other dataframe. For example, below we have people (including country) and brands (related to the people) and we want to select “only brands related to people who live in Nambia”:


First I get an array of first names, based on Namibia from my people dataframe – the .values attribute is important here because it ensures that the actual names are stored in the array as shown:

Screen Shot 2018-01-28 at 18.45.23

Then I extract brands by first name from brands, based on the first names that were related to Namibia in people:

Screen Shot 2018-01-28 at 18.45.44


Comments are closed.

Create a website or blog at

Up ↑

%d bloggers like this: