Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13861

Create & Insert data with schema of Dataframe

$
0
0

I have a csv that has 3300 attributes/columns. I cannot afford to create the columns manually in AZ SQL DB. I am looking out ways to automatically do it using Python. Came across to_sql and SQL Alchemy but does not look like it is working.

Error; ArgumentError: Expected string or URL object, got <pyodbc.Connection object at 0x0000022429404440>

import pandas as pdimport pyodbcimport urllibfrom sqlalchemy import create_enginefpath = r"C:\Users\***\test.csv"df = pd.read_csv(fpath)#print(df.head(5))conn = pyodbc.connect("DRIVER={ODBC Driver 17 for SQL Server};Server=tcp:XXX.database.windows.net,1433;DATABASE=XXX;UID=XXX;PWD=XXX")#;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;")engine = create_engine(conn)df.to_sql(name='test',con=engine, if_exists='append',index=False)

Viewing all articles
Browse latest Browse all 13861

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>