0

I'm attempting to combine different dataframes for NBA data. My first dataframe is from a basketball-reference page and my second dataframe is from a 538 stats page. I've already webscraped them.

I want to combine them so that it is by the player name. One of the dataframes is still bigger than the other. How can I combine the dataframes together? Both have the column id of "Player"

James
  • 25,833
  • 3
  • 34
  • 55
lydol
  • 63
  • 1
  • 8
  • Have you looked at [merge](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.merge.html?highlight=merge#pandas.DataFrame.merge)? – RufusVS Nov 24 '19 at 21:49

1 Answers1

0

I think you probably want to use pandas .merge().

import pandas as pd

df1 = pd.DataFrame({'player': ['foo', 'bar', 'baz', 'foo', 'bar', 'foo'],
               'value': [1, 2, 3, 5, 7, 9]})
df2 = pd.DataFrame({'player': ['foo', 'bar', 'baz', 'foo'],
                 'value': [5, 6, 7, 8]})

merged_df  = df1.merge(df2, how='outer', on='player')
Matthew Borish
  • 1,457
  • 1
  • 9
  • 19