0

Hello i want to check 4 conditions between 2 DataFrames and if all 4 the same take value of the column and put it to another column in the other DataFrame.

df1:

date time type full_name situation
2022-11-04 1 Goal Player1 EQ
2022-11-04 11 Goal Player3 PP

df 2:

date time full_name x y shot_result distance
2022-11-04 1 Player1 18.85 7.71 Goal 5.98
2022-11-04 12 Player1 17.98 8.55 Missed 44.29

wanted result:

date time full_name x y shot_result distance situation
2022-11-04 1 Player1 18.85 7.71 Goal 5.98 EQ
2022-11-04 12 Player1 17.98 8.55 Missed 44.29 NaN

I tried this:

for i in range(len(df2["shot_result"])):
    for j in range(len(df1["type"])):
        if df2["shot_result"][i] == df1["type"][j]:
            df2["situation"][i] = df1["situation"][j]

It works great but only for 1 condition. I need a working loop to loop through every condition.

EDIT: I have to check in this order:

If df2.shot_result == df1.type
--> if df2.date == df1.date
--> if df2.time == df1.time
--> if df2.full_name == df1.full_name
--> df2.situation = df1.situation

I need some help to solve the problem.

0 Answers0