[英]How to insert data into Oracle Database using Pandas?
嗨下面是我正在嘗試做的代碼連接字符串很好,當我運行時沒有錯誤彈出並且它也沒有更新數據庫你能幫我識別錯誤嗎?
並且我有兩個工作表里面的 excel 數據相同,只是第二個工作表名稱中的一列與性別相同
sample Dataframe which i want to insert into DB is
NAME AGE
0 x 21
1 y 22
2 z 23
3 m 24
4 t 35
import cx_Oracle
from sqlalchemy import create_engine
engine = Create_engine('oracle+cx_oracle://<Connection Detail>')
DB_Connection = cx_Oracle.connect(<Connection Detail)
mycursor = DB_Connection.cursor()
sample_excel = pd.ExcelFile(r<file Path>)
sample_excel_sheet = sample_excel.sheet_names
for i in sample_excel_sheet:
sheet_data = pd.read_excel(r<file Path>,sheet_name=i)
sheet_namee = i.upper()
with engine.connect() as connection:
sheet_data.to_sql(name='sheet_namee',con=engine, if_exists='replace')
DB_Connection.commit()
你只需要改變
name='sheet_namee'
和
name=sheet_namee
因為sheet_namee = i.upper()
已經返回帶引號的工作表名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.