0

I have two data frames. I want to select all rows in one dataframe where a particular column is equal to a column in a different data frame, as well as being inside 5 years older or younger than their age.

I have two dataframes, df:

Name    Gender   Age
John    Male     20
Joe     Male     23
Sarah   Female   34
Tim     Male     41
Amy     Female   22

and df1:

Name    Gender   Age
Tom     Male     24

I want to create a new data frame that displays the rows of df that have the same gender as df1, so basically have a data frame where the gender for all rows is male in this case. I want to avoid saying gender = male however. Then, these people also have to be within five years of Tom, so between 19 and 29. The output should be like so.

Name    Gender   Age
John    Male     20
Joe     Male     23

Thanks in advance...

toothsie
  • 245
  • 3
  • 10

0 Answers0