In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use pandas to merge multiple lines in python, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
There is a need to append the original value after summing the column sum. This requires a multi-line merge.
After grouping according to name, sum and add a column to show the original value
# define functions to separate merged data with commas
> > def joinValues (df):
Return', '.join (df.astype (' str'))
# use the agg function to sum and merge separately
> ds = df.groupby (by='name'). Agg ({'sum', joinValues: [' sum', joinValues]})
> ds
C
Sum joinValues
Name
Lb 88 88
Lc 91 45,23,23
# reset index
> > ds.reset_index ()
Name C
Sum joinValues
0 lb 88 88
1 lc 91 45,23,23
#
Ds.to_excel (ringing DVOGRAPHY excel Universe res.xlsx')
The results are as follows:
The above is how to use pandas to merge multiple lines in python. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.