知識點:pandas + Oracle
from sqlalchemy import create_engine import pandas as pd con = create_engine('oracle+cx_oracle://用戶名:密碼@IP:埠/庫名?charset=utf8') sql = "select * from addressinfo where rownum < 11" df = pd.read_sql(sql, con)
df.to_csv('5.csv', header=True, index=False, encoding='utf_8_sig')
報錯:出現中文亂碼
解決:encoding='utf_8_sig'
header : 是否保存列名,默認為 True ,保存
index : 是否保存索引,默認為 True ,保存
SQLAlchemy庫建立對應的資料庫連接,使用create_engine函式,建立一個資料庫連接,pandas支持的資料庫有Oracle、MySQL、SQLServer和SQLite等主流資料庫
參考檔案:
https://blog.csdn.net/weixin_43133808/article/details/87453573
Python獲取Oracle資料并保存:https://blog.csdn.net/weixin_40733475/article/details/79136123
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/148131.html
標籤:Python
