Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand python with merge

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to carry on the merge understanding of python, I believe that many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Merge

Pandas's merge method provides a memory linking operation similar to SQL, and the official website documentation mentions that its performance will be more efficient than data manipulation in other open source languages (such as R).

The comparison with the SQL statement can be seen here

Parameters of merge

On: column name, the name of the column that join uses to align. When using this parameter, make sure that the column used by the left table and the right table to align has the same column name.

Left_on: the left table-aligned column, which can be a column name or an arrays of the same length as dataframe.

Right_on: the right-hand table-aligned column, which can be either a column name or an arrays of the same length as dataframe.

Left_index/ right_index: in the case of True's haunted, index is used as the aligned key

How: the method of data fusion.

Sort: sorts the keys merged by dataframe in dictionary order. By default, if false is set, performance can be improved.

The default merge method for merge: merge is used for merging within the table based on index-on-index and index-on-column (s), but the default is based on index. 121.1 Composite key merge method when using merge, you can select multiple key as composite to align and merge. 11.1.1 specify the columns In for data merge alignment through on [41]: left = pd.DataFrame ({'key1': [' K0','K0','K1','K2'],....: 'key2': [' K0','K1','K0','K1'],....:'A0' In [42]: right = pd.DataFrame ({'key1': [K0, K1, K2]). ...: 'key2': [' K0','K0'],....:'C': ['C _ 0','C _ 1','C _ 2'],'D': ['D _ 0','D _ 1','D _ 2' ): In [43]: result = pd.merge (left, right, on= ['key1',' key2']) 12345678910111213345678910111213

If how is not specified, the inner method is used by default.

The methods of how are:

Left

Keep only all the data in the left table

In [44]: result = pd.merge (left, right, how='left', on= ['key1',' key2']) 11

Right

Keep only all the data in the right table

In [45]: result = pd.merge (left, right, how='right', on= ['key1',' key2']) 11

Outer

Keep all the information for the two tables

In [46]: result = pd.merge (left, right, how='outer', on= ['key1',' key2']) 11

Inner

Keep only the information in the common part of the two tables

In [47]: result = pd.merge (left, right, how='inner', on= ['key1',' key2']) 11

Think about it: if the key value of left,right is inconsistent with the name, how should it be associated

After reading the above, have you mastered how to understand the merge of python? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report