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 change multiple lines to one line by Mysql

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

Share

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

This article mainly introduces "Mysql how to achieve multi-line to one line". In daily operation, I believe many people have doubts about how to achieve multi-line change in Mysql. The editor consulted all kinds of materials 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 multi-line change to one line in Mysql". Next, please follow the editor to study!

Import pandas as pd

Df = pd.read_excel ('learn multiline strings grouped into one line .xlsx',)

The python method is merged into a list re = df.groupby (['company', 'responsible person']) ['mobile phone number'] .apply (list) .reset_index ()

# # or pd.DataFrame (df.groupby (['company', 'responsible person']) ['mobile phone number'] .apply (list))

Re

Python method 2 apply string average # df.groupby (['company', 'responsible person']) ['mobile phone number'] .apply (lambda x: '.join (x.to_string (index=False) .str.replace (' (\ n)','). Reset_index ()

Df ['mobile phone number'] = df ['mobile phone number'] .astype (str)

Df.groupby (['company', 'responsible person']) ['mobile phone number'] .apply (lambda x:', '.join (x)) .reset_index ()

The Mysql method: group_concat () is saved to the database import time

Import requests

Import json

Import os

Import pandas as pd

Import warnings

Import arrow

From sqlalchemy import create_engine

Import sys

From sqlalchemy import text

If sys.version_info.major

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