Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

what is avc

Answered: 1 week ago

Question

Explain the key areas in which service employees need training.

Answered: 1 week ago

Question

Understand the role of internal marketing and communications.

Answered: 1 week ago