Learn the hard core operation of Python in one minute

Given two data tables: left and right, they have at least one column with the same name. The name is assumed to be a key. How to connect these two tables?

Python provides a merge operation to accomplish this.

The keys of the left table are: k0, k1, k2; the keys of the right table are: k0, k0, k1

**1) **If the key ** of the left table points to the ** right table, then this connection method is called how: left: The relationship diagram is expressed as follows:

left    right
k0      k0
  k0
k1      k1
k2      NaN

**2) **If the key ** of the right table points to the ** left table, then this connection method is called how: right

right  left
k0      k0
k0      
k1      k1

**3) **If only the shared key of the left and right tables is used to establish a relationship, then this connection method is called how: inner

left  right
k0     k0
k0     k0
k1     k1

**4) **If a relationship is established after the keys of the left and right tables are merged, the connection method is called how: outer

left  right
k0     k0
  k0
k1     k1
k2     NaN

**The above are the 4 ways to establish a relationship based on the key node when connecting two tables in merge. **

The following example is verified

Left and right table data:

left
 age1   key
010 k0
120 k1
230 k2

right
 age2   key
040 k0
150 k0
260 k1

**how = 'left' **

pd.merge(left,right,how='left',on='key')
 age1   key   age2
010 k0   40.0110   k0   50.0220   k1   60.0330   k2   NaN

**how = 'right' **

pd.merge(left,right,how='right',on='key')
age1   key   age2
010 k0   40110   k0   50220   k1   60

how = 'inner'

pd.merge(left,right,how='inner',on='key')
age1   key   age2
010 k0   40110   k0   50220   k1   60

how = 'outer'

pd.merge(left,right,how='outer',on='key')
age1   key   age2
010 k0   40.0110   k0   50.0220   k1   60.0330   k2   NaN

**- - - - - - - - - - - - - - - - - - - - - ** End ---------------------

Recommended Posts

Learn the hard core operation of Python in one minute
Learn Python in one minute | Object-oriented (Chinese)
Learn Python in one minute | Python functions (on)
Learn Python in One Minute | Object Oriented (Part 1)
The usage of wheel in python
The operation of python access hdfs
The usage of tuples in python
Understanding the meaning of rb in python
Learn the basics of python interactive mode
The usage of Ajax in Python3 crawler
What is the function of adb in python
Python implements the shuffling of the cards in Doudizhu
The meaning and usage of lists in python
The consequences of uninstalling python in ubuntu, very
Example of feature extraction operation implemented in Python
How to understand the introduction of packages in Python
Consolidate the foundation of Python (4)
Consolidate the foundation of Python(7)
Subscripts of tuples in Python
Consolidate the foundation of Python(6)
How to find the area of a circle in python
Consolidate the foundation of Python(5)
Consolidate the foundation of Python (3)
Summary of logarithm method in Python
Use of Pandas in Python development
Python preliminary implementation of word2vec operation
Python handles the 4 wheels of Chinese
Implementation of python selenium operation cookie
Use of numpy in Python development
Python simulation of the landlord deal
What is the use of Python
Detailed usage of dictionary in Python
Usage of os package in python
Learn about garbage collection in Python
​What are the numbers in Python?
Some examples of python operation redis
Talking about the modules in Python
Example operation of python access Alipay
The premise of Python string pooling
Secrets of the new features of Python 3.8
The father of Python joins Microsoft
End the method of running python
Description of in parameterization in python mysql
Detailed explanation of the use of pip in Python | summary of third-party library installation
Can Python implement the structure of the stack?
What are the required parameters of python
Implementation of JWT user authentication in python
Logistic regression at the bottom of python
Python solves the Tower of Hanoi game
Solve the conflict of multiple versions of python
What is the scope of python variables
Python implements the sum of fractional sequences
Two days of learning the basics of Python
What is the id function of python
Analysis of glob in python standard library
Where is the pip path of python3
Method of installing django module in python
The essence of Python language: Itertools library
What are the advantages of python language
The specific method of python instantiation object
python3 realizes the function of mask drawing