错误的标记数据。 C错误:预期在第93行中的5个字段,SAW 8

发布于 2025-02-10 21:59:42 字数 2007 浏览 0 评论 0原文

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文