Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

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

Shulou Source: shulou.com Published: 2022-06-03 03:11:55 10月02日 Update

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)

Tags: Data file format database path code first part address password object serial number nonsense user user name link learning interpretation actual combat data analysis analysis Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Shulou Information Xiaomi NVidia