In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to achieve table join in Pandas". In daily operation, I believe many people have doubts about how to achieve table join in Pandas. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubt of "how to achieve table join in Pandas". Next, please follow the editor to study!
Connection object (Concatenating) pd.concat (objs, axis=0, join='outer', join_axes=None, ignore_index=False, keys=None, levels=None, names=None, verify_integrity=False, copy=True)
Join has two parameters, inner (inward) and outer (outer).
Ignore_index: whether to ignore the index, which is not ignored by default, and will be connected according to the index.
Join_axes: index of which data frame to use
Keys: composite index
Horizontal connection In [1]: df1 = pd.DataFrame ({'Aids: [' A0,'A1,'A2,'A3],...:'B0,'B1,'B2,'B3],...:'C: ['C 0,'C 1, C 2, C 3] ...: index= [0,1,2,3].: In [8]: df4 = pd.DataFrame ({'Baking: [' B2,'B3,'B6,'B7]] ...: index= [2,3,6,7].: result = pd.concat ([df1, df4], axis=1. Join_axes= [df1.index])
Longitudinal connection
In [15]: result = pd.concat ([df1, df4], ignore_index=True)
The append function is more efficient than the database connection (joining/merging).
This syntax is specifically set for those who use SQL data.
Pd.merge (left, right, how='inner', on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=True, suffixes= ('_ x','_ y'), copy=True, indicator=False)
Left: left data tabl
Right: right datasheet
On: which column is used to join the table? if there are no input parameters, it will be based on the common index.
Left_on: use the data box on the left as join key
Right_on: use the data box on the right as join key
Left_index: use the index on the left as the join key
Right_index: use the index on the right as the join key
How:left right out inner, default is inner
Sort: sort the results through join key
Suffixes:
Copy:
Indicator:
Merge is also an object method, and the object defaults to a left-linked table. The join instance method defaults to the index as the join method.
In [38]: left = pd.DataFrame ({'key': [' K0','K1','K2','K3'],....:'A3': ['A0','A1','A2','A3'],....: ['B0','B1','B2' ('B3']})....: In [39]: right = pd.DataFrame ({' key': ['K0','K1','K2','K3'],....:'C0','C1','C2','C3'],....: 'Dao: [' D0','D1' ): In [40]: result = pd.merge (left, right, on='key')
Use indicator to monitor the status of the connection
In [48]: df1 = pd.DataFrame ({'col1': [0,1],' col_left': ['asides,' b']}) In [49]: df2 = pd.DataFrame ({'col1': [1,2,2],' col_right': [2,2,2]}) In [50]: pd.merge (df1, df2, on='col1', how='outer') Indicator=True) Out [50]: col1 col_left col_right _ merge0 0 a NaN left_only1 1 b 2.0 both2 2 NaN 2.0 right_only3 2 NaN 2.0 right_only here The study on "how to achieve table join in Pandas" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.