-2

I am trying to join two dataframes with different names.

dataframe dataframe

newframe = pd.merge(detailedresults,seeds, how = 'left', left_on = ['Season', 'WTeamID','LTeamID'], right_on = ['Season','TeamID'])

I am trying to merge them by doing this. I am receiving this error

ValueError: len(right_on) must equal len(left_on)

How am I able to fix this?

Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
  • 1
    Does this answer your question? [Pandas Merging 101](https://stackoverflow.com/questions/53645882/pandas-merging-101) – Codemaster Apr 18 '21 at 21:06
  • 1
    your keys _must_ be the same on both sides of the merge, `WTeamID` is only on the left what are you trying to join it on? you most likely need to `melt` your first dataframe to match the shape of the 2nd, please see [mcve] and [ask] – Umar.H Apr 18 '21 at 21:16

1 Answers1

0

What's the issue with changing left_on=['Season','WTeamID'] or left_on=['Season','LTeamID']. Please provide some more information on what "WTeamID" and "LTeamID" represent.

VminVsky
  • 50
  • 7
  • I think you just unintentionally solved my problem. The issue is that WTeamId and LTeamId share the value TeamID in the right dataframe, but they are two separate columns in the left dataframe. I needed two separate values from the same column in the right dataframe for each row in the left dataframe I just ended up merging the dataframe twice with each separate value. – ieatnoobs11239 Apr 18 '21 at 21:23
  • Also take a look at the ```pd.melt``` operation. – VminVsky Apr 18 '21 at 21:25