Python pandas的DataFrame导出到CSV和数据库

一、导出到CSV

使用to_csv方法,导出到csv文件。

# to_csv
import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.randn(4, 4))
df.to_csv('./df1.csv', sep = ',', header = ['col1','col2','col3','col4','col5','col6'], index = False)

二、导出到数据库

# database oracle
from sqlalchemy import create_engine
import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(4, 4))
conn_string='x1://dir:[email protected]:999/orcl'
engine = create_engine(conn_string, echo=False)
df.to_sql('dbase', con=engine)

引用

【1】https://pandas.pydata.org/pandas-docs/version/0.21/generated/pandas.DataFrame.to_csv.html

你可能感兴趣的:(Python,python,csv,机器学习,深度学习)