Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using Python 3.6 and SQL Server I have coded the following to connect to a SQL server and add data from a csv file I
Using Python 3.6 and SQL Server I have coded the following to connect to a SQL server and add data from a csv file I downloaded. I created a table and added the data.(I think) How would I query the data by the top 50 rows? And how would I query the data by the highest years, again like 50 rows? import pyodbc connection_string = 'DRIVER={XXX XXX};SERVER=XX.XX.XX.XXX;DATABASE=MIS5400;UID=mis5400;PWD=Mi$5400' conn = pyodbc.connect(connection_string,autocommit=True) curs = conn.cursor() curs.execute( ''' create table Unemployment_Rate_Mecham( ID int primary key clustered identity(1,1) ,ObservationDate datetime ,CPIAUCSL float ) ''' ) import csv insert_query = 'insert into Unemployment_Rate_Mecham (ObservationDate, CPIAUCSL) values (?,?)' with open(r'C:\Users\Nathan\Desktop\MIS 5400\UNRATE.csv', 'r',encoding='utf8') as cpi_file: cpi = csv.reader(cpi_file) curs.executemany(insert_query, cpi) conn.commit() conn.close() conn = pyodbc.connect(connection_string,autocommit=True) curs = conn.cursor()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started