Skip to content

Instantly share code, notes, and snippets.

@dyerrington
Created November 3, 2015 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyerrington/5fe39f81b9bc1b0f4db1 to your computer and use it in GitHub Desktop.
Save dyerrington/5fe39f81b9bc1b0f4db1 to your computer and use it in GitHub Desktop.
Basic left join example using pandas data frames.
test_1 = pd.DataFrame([['Test 1', 'Dogs', 'Cats'], ['Test 2', 'Fogs', 'Squids']], columns=['Company', 'A1', 'A2'])
test_2 = pd.DataFrame([['Test 1', 4, 5, 6], ['Test 1', 6,3,1], ['Test 1', 3, 3, 1], ['Test 2', 2,3 ,4], ['Test 2', 7, 8, 9]], columns=['Company', 'V1', 'V2', 'V3'])
pd.merge(left=test_2, right=test_1, how='left', left_on='Company', right_on='Company')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment