Merge Two DataFrames in Python

  • left − A DataFrame object.
  • right − Another DataFrame object.
  • on − Columns (names) to join on. Must be found in both the left and right DataFrame objects.
  • left_on − Columns from the left DataFrame to use as keys. Can either be column names or arrays with length equal to the length of the DataFrame.
  • right_on − Columns from the right DataFrame to use as keys. Can either be column names or arrays with length equal to the length of the DataFrame.
  • left_index − If True, use the index (row labels) from the left DataFrame as its join key(s). In the case of a DataFrame with a MultiIndex (hierarchical), the number of levels must match the number of join keys from the right DataFrame.
  • right_index − Same usage as left_index for the right DataFrame.
  • how − One of 'left', 'right', 'outer', 'inner'. Defaults to inner. Each method has been described below.
  • sort − Sort the result DataFrame by the join keys in lexicographical order. Defaults to True, setting to False will improve the performance substantially in many cases.
create 2 DataFrame to the demo merge operation
merge based on ‘subject_id’
Here we merge based on id and subject_id
Left and Right Joins
Outer join

--

--

--

www.linkedin.com/in/ankurjavaarch

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Unity Animations

Dart Extensions Methods

300 Interview Questions , Challenges for Docker , Docker Swarm, Docker Certified Associate…

Running a series of Cloud Study Jams

Considering becoming a Software Engineer?

Why we built ‘Proctor’ — An Automation Orchestrator

5 Lessons I Learned From Building a Web App With Flutter

Secure Your Applications Using AWS Rekognition

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ankur Agarwal

Ankur Agarwal

www.linkedin.com/in/ankurjavaarch

More from Medium

Activation functions for Neural Networks

ATTRITION PREDICTION MODEL

GRID Predictions Part 1: Player Ratings

Dicretizing Data In MATLAB(Illustrated with codes)