用pyodc导出to_Sql熊猫

时间:2020-04-09 12:09:51

标签: sql-server pyodbc

我正在尝试将我的数据表导入MySQL数据库

    df = df[["name","country"]]
    df[["name"]] = df[["name"]].astype(str)
    df[["country"]] = df[["country"]].astype(str)

    print(df.dtypes)
    print(df)

    name        object
    country    object

    name        country
0   jame        usa   
1   luke        canada

当我尝试使用mssql和pyodbc导入MSSql数据库

conn = "DRIVER={ODBC Driver 17 for SQL Server};SERVER=data;DATABASE=db;UID=root;PWD=password"
quoted = quote_plus(conn)
new_con = "mssql+pyodbc:///?odbc_connect={}".format(quoted)
engine = create_engine(new_con)

@event.listens_for(engine, "before_cursor_execute")
def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany):
    print("FUNC call")
    if executemany:
        cursor.fast_executemany = True


df.to_sql(df, engine, index=False, if_exists="append", schema="dbo")

返回“ TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed".,这是什么问题。我在DF数据帧之前在表之间进行了一些联接,这意味着我具有不同的数据类型吗?

0 个答案:

没有答案