Working with an NFL dataset with pandas containing all offensive player stats for week 1 of the 2019 season. I currently have three DataFrames, one for passing stats, rushing stats, and receiving stats. I want to combine all three DataFrames into one final DataFrame. The problem is that some players appear in one or more DataFrames. For example, a QB can run and pass the ball, so some QB's appear in both the passing DF and the rushing DF. "Player" is the common index I want to combine them on, but each duplicated row will also have in common the 'Pos' and 'Tm' value. So I want to combine these three DataFrames on the columns 'Player', 'Tm' and 'Pos'.
I currently have each DataFrame saved to a variable in a list named dfs.
I tried
df = dfs[0].join(dfs[1:])
but that results in giving me a DataFrame with one row - Julian Edelman - the only player who ran, passed, and caught the ball in week 1 of the 2019 season. Suffice to say that's not what I'm looking for.
Copied below is the first five rows of each of the DataFrames.
Pos Tm PassingYds PassingTD Int PassingAtt Cmp
Player
Lamar Jackson QB BAL 324 5 0 20 17
Dak Prescott QB DAL 405 4 0 32 25
Robert Griffin QB BAL 55 1 0 6 6
Patrick Mahomes QB KAN 378 3 0 33 25
Kirk Cousins QB MIN 98 1 0 10 8
--------------------------------------------------------------------------
Pos Tm Rec Tgt ReceivingYds ReceivingTD
Player
Sammy Watkins WR KAN 9 11 198 3
Michael Gallup WR DAL 7 7 158 0
John Ross WR CIN 7 12 158 2
DeSean Jackson WR PHI 8 9 154 2
Marquise Brown WR BAL 4 5 147 2
---------------------------------------------------------------------------
Pos Tm RushingAtt RushingYds RushingTD
Player
Marlon Mack RB IND 25 174 1
Christian McCaffrey RB CAR 19 128 2
Saquon Barkley RB NYG 11 120 0
Dalvin Cook RB MIN 21 111 2
Mark Ingram RB BAL 14 107 2