pandas讀取Oracle數據庫數據並保存


知識點: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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM