Data analysis using Python (12) Pandas: Data merge

Source: Internet
Author: User
Tags instance method


Pandas provides three main ways to merge data:
    • Pandas.merge () method: merging of database styles;
    • Pandas.concat () method: An axial connection that stacks multiple objects together along an axis;
    • instance Method Combine_first () method: merges overlapping data.

Pandas.merge () method: Merging of database StylesFor example, merging two dataframe with the merge () method: on= ' name ' means to use the Name column as a key; By default, merge does an inner join (inner), which is the intersection of keys. There are other ways to connect left, right, and outer (outer). For example, specify the merge that you just had as a left connection:
Try the external connection again, and the result is the set of the key:
The first three merges are the column names as the connection keys, and Dataframe also has a join () method that can be indexed as a connection key, for example:   Pandas.concat () method: inline joins, that is, to stack multiple objects together along an axisFor example: By default, Concat is connected on the vertical axis (axis=0), which results in a new series. If you want to connect in the horizontal direction, pass in the Axis=1, for example:
instance Method Combine_first () method: Merge overlapping DataFor example: This method is equivalent to: it does a vectorization of the if-else operation, if the S1 in a location of the data is empty, then use S2 the same position on the element to complement, you can be understood as "patching" operation.
The next essay is: Data analysis using Python (13) Pandas: Data conversion, interested friends Welcome to pay attention to this blog, but also welcome you to add comments to discuss.

Data analysis using Python (12) Pandas: Data merge

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.