Python Forum
Time SQL Statement & Display Total
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time SQL Statement & Display Total
#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


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,899 May-06-2023, 08:14 AM
Last Post: pramod08728
  Real time Detection and Display Gilush 0 1,782 Feb-05-2022, 08:28 PM
Last Post: Gilush
  splitting total time between days tester_V 7 3,036 Nov-14-2020, 04:40 AM
Last Post: tester_V
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 2,220 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  calling strftime does not display current time tonytech 2 2,125 May-05-2020, 04:53 AM
Last Post: tonytech
  How to Display Multiple Time Tables With While Loop ZQ12 2 2,156 Nov-10-2019, 04:15 AM
Last Post: ZQ12
  export file and display cmd prompt same time jacklee26 1 2,023 Jul-24-2019, 05:15 AM
Last Post: Larz60+
  Display 20 records at a time,data structure or loop pythonds 1 2,451 Mar-29-2018, 11:09 AM
Last Post: DeaD_EyE
  Graphic of total different connection opened by one ip (per seconds) by time FoxModem56k 0 3,185 May-25-2017, 03:27 PM
Last Post: FoxModem56k

Forum Jump:

User Panel Messages

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