Python Forum
Result Set Count and Timing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Result Set Count and Timing
#1
Hello,

I'm experimenting with panda and sqlalchemy for the first time where I'm importing a CSV file into a SQL Server database.

from sqlalchemy import create_engine, func
import pandas as pd
import urllib
import pyodbc

database = {'servername': 'local',
            'database': 'AdventureWorks2012',
            'driver': 'driver=SQL Server Native Client 11.0'}
names = ['Title', 'FirstName', 'LastName']

readFile = "C:/Temp/aw2012_exp.csv"
# create the connection
engine = create_engine('mssql+pyodbc://' + database['servername'] + '/' + database['database'] + "?" + database['driver'])

df = pd.read_csv(readFile, names = names, header = None, encoding = "utf-8")
df.to_sql(name = 'Python', schema = 'Person', con = engine, if_exists = 'replace', index = False)

#result = engine.execute('SELECT COUNT(*) FROM PERSON.PYTHON')


#cnt = pd.read_sql('SELECT COUNT(*) FROM Person.Python', engine)
#print(cnt)
#result.fetchall()
I'd like to be able to output the timing of the insert as well as the count of the records inserted. The 'print[cnt]' doesn't seem like the best way to handle this.

Any feedback on script and timing/count would be great!

Thanks for you help!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020