错误的标记数据。 C错误:预期在第93行中的5个字段,SAW 8
使用pandas和numpy读取Excel文件并在上述Excel文件上创建SQL表...除了编码源文件时我遇到的错误外,代码中的所有内容似乎都
在此是我的代码:
import pandas as pd
import pyodbc
# Import CSV
data = pd.read_csv (r"C:\Users\c.stembridge\OneDrive - NEWREST GROUP SERVICES\Overtime Forecast Report.xlsx", sep=',', encoding='cp437')
df = pd.DataFrame(data)
# Connect to SQL Server
conn = pyodbc.connect("DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost;UID=SA;PWD=Working@2022;DATABASE=testdb;Encrypt=no;TrustServerCertificate=yes")
cursor = conn.cursor()
# Create Table
cursor.execute('''
CREATE TABLE Overtime_Forecast (
date nvarchar(10) primary key,
day nvarchar(9),
hrs int,
dl int,
catered int,
hrs_diff_btwn_last_day int,
catered_flight_diff int,
employees_OT_count int,
carriers int,
full int,
half int,
total_carts int
)
''')
# Insert DataFrame to Table
for row in df.itertuples():
cursor.execute('''
INSERT INTO Overtime_Forecast (
date nvarchar(10) primary key,
day nvarchar(9),
hrs int,
dl int,
catered int,
hrs_diff_btwn_last_day int,
catered_flight_diff int,
employees_OT_count int,
carriers int,
full int,
half int,
total_carts int)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
''',
row.date,
row.day,
row.hrs,
row.dl,
row.catered,
row.hrs_diff_btwn_last_day,
row.catered_flight_diff,
row.employees_OT_count,
row.carriers,
row.full,
row.half,
row.total_carts
)
conn.commit()
似乎无法弄清楚什么当我使用其他问题中的许多解决方案来解决这一范围时,可以解决错误
Using pandas and numpy to read an excel file and create sql table upon said excel file... everything in the code seems to work find besides the error I get when encoding the source file
Here's my code:
import pandas as pd
import pyodbc
# Import CSV
data = pd.read_csv (r"C:\Users\c.stembridge\OneDrive - NEWREST GROUP SERVICES\Overtime Forecast Report.xlsx", sep=',', encoding='cp437')
df = pd.DataFrame(data)
# Connect to SQL Server
conn = pyodbc.connect("DRIVER={ODBC Driver 18 for SQL Server};SERVER=localhost;UID=SA;PWD=Working@2022;DATABASE=testdb;Encrypt=no;TrustServerCertificate=yes")
cursor = conn.cursor()
# Create Table
cursor.execute('''
CREATE TABLE Overtime_Forecast (
date nvarchar(10) primary key,
day nvarchar(9),
hrs int,
dl int,
catered int,
hrs_diff_btwn_last_day int,
catered_flight_diff int,
employees_OT_count int,
carriers int,
full int,
half int,
total_carts int
)
''')
# Insert DataFrame to Table
for row in df.itertuples():
cursor.execute('''
INSERT INTO Overtime_Forecast (
date nvarchar(10) primary key,
day nvarchar(9),
hrs int,
dl int,
catered int,
hrs_diff_btwn_last_day int,
catered_flight_diff int,
employees_OT_count int,
carriers int,
full int,
half int,
total_carts int)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)
''',
row.date,
row.day,
row.hrs,
row.dl,
row.catered,
row.hrs_diff_btwn_last_day,
row.catered_flight_diff,
row.employees_OT_count,
row.carriers,
row.full,
row.half,
row.total_carts
)
conn.commit()
can't seem to figure out what could solve the errors as I used many solutions from other questions to get this far
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论