0

Right now my dataframes look like this (I simplified it cause the original has hundreds of rows)

import pandas as pd

Winner=[[1938,"Italy"],[1950,"Uruguay"],[2014,"Germany"]]
df=pd.DataFrame(Winner, columns=['Year', 'Winner'])
print(df)

MatchB=[[1938,"Germany",1.0],[1938,"Germany",2.0],[1938,"Brazil",1.0],[1950,"Italy",2.0],[1950,"Spain",2.0],[1950,"Spain",1.0],[1950,"Spain",1.0],[1950,"Brazil",1.0],
[2014,"Italy",2.0],[2014,"Spain",3.0],[2014,"Germany",1.0]]
df2B=pd.DataFrame(MatchB, columns=['Year', 'Away Team Name','Away Team Goals'])
df2B

I would like to filter df2B so that I will have the rows where the "Year" and "Away Team Name" match df:

Filtered List (Simplified)

I check google but can't find anything useful

Chery
  • 5
  • 1
  • 1
    Does this answer your question? [How do I select rows from a DataFrame based on column values?](https://stackoverflow.com/questions/17071871/how-do-i-select-rows-from-a-dataframe-based-on-column-values) – RMS Nov 27 '22 at 02:04

1 Answers1

0

You can merge.

df = pd.merge(left=df, right=df2B, left_on=["Year", "Winner"], right_on=["Year", "Away Team Name"])
print(df)

Output:

   Year   Winner Away Team Name  Away Team Goals
0  2014  Germany        Germany              1.0
Jason Baker
  • 3,170
  • 2
  • 12
  • 15