In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use the join function in pandas, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
Join
Join is a bit like append to concat, for data consolidation.
Df.join (other: 'FrameOrSeriesUnion', on:' IndexLabel | None' = None, how: 'str' =' left', lsuffix: 'str' ='', rsuffix: 'str' ='', sort: 'bool' = False,)->' DataFrame'
In the function method, the key parameters have the following meanings:
Other: right side data for merging
On: connect key fields, both in the left and right data need to exist, otherwise use left_on and right_on
How: data connection method. Default is inner. Optional outer, left and right
Lsuffix: the suffix of the same name on the left
Rsuffix: the suffix of the same name column on the right
Next, we will demonstrate the function of this function.
In [71]: df = pd.DataFrame ({'key': [' K0','K1','K2','K3','K4','K5'],...:'A3','A1','A2','A3','A4','A5']}) In [72]: other = pd.DataFrame ({'key': [' K0','K1') In [73]: dfOut [73]: key A0 K0 A01 K1 A12 K2 A23 K3 34 K4 A45 K5 A5In [74]: otherOut [74]: key B0K0B01 K1 B12 K2 B2In [75]: df.join (other, on='key') Traceback (most recent call last):... ValueError: You are trying to merge on object and int64 columns. If you wish to proceed you should use pd.concat
If you want to use the key keyword, you need key to be an index.
Specify key
In [76]: df.set_index ('key') .join (other.set_index (' key')) Out [76]: a Bkey K0 A0 B0K1 A1 B1K2 A2 B2K3 A3 NaNK4 A4 NaNK5 A5 NaNIn [77]: df.join (other.set_index ('key'), on='key') Out [77]: key A B0 K0 A0 B01 K1 A1 B2 K23 K3 NaN4 K4 NaN5 K5 A5 NaN
Specify duplicate column suffix
In [78]: df.join (other, lsuffix='_ left', rsuffix=' right') Out [78]: key_ left A key right B0 K0 A0 K0 B01 K1 A1 K1 B12 K2 A2 K2 B23 K3 A3 NaN NaN4 K4 NaN NaN5 K5 A5 NaN NaN
Other parameters will not be introduced, which is basically the same as merge.
Thank you for reading this article carefully. I hope the article "how to use join function in pandas" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.