Part we learned to read data pandas, and this time we take a look at how data is stored, the code line and up ~
csv file
Format: to_csv (file path, sep = '', index = TRUE, header = TRUE)
The default index is true, with line number
header default is true, with the column name
from pandas import DataFrame
from pandas import Series
# Made data
df=DataFrame({'age':Series([26,85]),'name':Series(['xiaoqiang1','xiaoqiang2'])})
df
# Deposit
df.to_csv('d:\1.csv')
excel file
Format: to_excel (file path, index = TRUE, header = TRUE)
Explained above, not nonsense
from pandas import DataFrame
from pandas import Series
# Made data
df=DataFrame({'age':Series([26,85]),'name':Series(['xiaoqiang1','xiaoqiang2'])})
df
# Deposit
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 username: password @ fill fill ip: 3306 / fill in the name of the database charset = utf8?')
# Made data
df=DataFrame({'age':Series([26,85]),'name':Series(['xiaoqiang1','xiaoqiang2'])})
df.to_sql(name=表名, con=engine, if_exists='append', index=False, index_label=False)