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 from one line to multiple lines in Mysql

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

Share

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

This article introduces the relevant knowledge of "how to turn Mysql into multiple lines". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Read data # data read

Import pandas as pd

Df= pd.read_excel ('. / excel one line turns to multiple lines .xlsx')

# # split

Df ['sales details (products and quantities)'] .str.split (';', expand = True)

Df ['sales details (products and quantities)'] .str.split (';', expand = True). Stack (). Reset_index (level = 1, drop = True) .rename ('sales details')

Df.drop ('sales details (products and quantities)', axis = 1) .join (df ['sales details (products and quantities)'] .str.split (';', expand = True). Stack ()\

.reset _ index (level = 1, drop = True)\

.rename ('sales details')

If you find a duplicate line, how to fix it?

The length of the Chinese seal is 3, so it needs to be divided by 3.

From sqlalchemy import create_engine

Import pandas as pd

From sqlalchemy import text

From warnings import filterwarnings

# since create table if not exists always throws warning, use filterwarnings to eliminate

Filterwarnings ('ignore') #, category = MySQLdb.Warning

Engine=create_engine ('mysql+pymysql://root:root@localhost:3306/cda')

Sql_1 = 'SELECT a

SUBSTRING_INDEX (

SUBSTRING_INDEX (b,';', mh.help_topic_id + 1)

';',-1)

FROM row2

LEFT JOIN mysql.help_topic mh ON mh.help_topic_id

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