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

Big data Analysis based on python-pandas data Storage (Code practice)

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

Share

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

In the last part, we learned how to read data from pandas. This time, let's take a look at how to store the data, and the code will be rolled up.

Csv file

Format: to_csv (file path, sep='', index=TRUE, header=TRUE)

Index defaults to true with a line serial number

Header defaults to true with column name

From pandas import DataFrame

From pandas import Series

# create data

Df=DataFrame ({'age':Series ([265.85]),' name':Series (['xiaoqiang1','xiaoqiang2'])})

Df

# deposit in

Df.to_csv ('d:\ 1.csv')

Excel file

Format: to_excel (file path, index=TRUE, header=TRUE)

Explain the same as above, not nonsense

From pandas import DataFrame

From pandas import Series

# create data

Df=DataFrame ({'age':Series ([265.85]),' name':Series (['xiaoqiang1','xiaoqiang2'])})

Df

# deposit in

Df.to_excel ('d:\ 1.xlsx')

Mysql

Format: to_sql (name= table name, con= database link object)

From pandas import DataFrame

From pandas import Series

From sqlalchemy import create_engine

Engine=create_engine ('mysql+pymysql:// fill in user name: fill in password @ fill in ip address: 3306 / fill in database name? charset=utf8')

# create data

Df=DataFrame ({'age':Series ([265.85]),' name':Series (['xiaoqiang1','xiaoqiang2'])})

Df.to_sql (name= table name, con=engine, if_exists='append', index=False, index_label=False)

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