Posts

Connecting to SQL Server using Python

Image
Updating record from CSV file to SQL Server using Python In this post, I will be showing you how to read a CSV file. And then insert the records to SQL Server. Starting with reading the CSV file from my desktop. And adding a few transformations to the data. Before we do that make sure the below libraries are available on your IDE. pandas pyodbc datetime Pandas: Using it for adding the read data to a dataframe and apply a few changes like filling the blanks, setting the datatypes of the columns, etc. Pyodbc: To easily set a connection to data sources with an ODBC driver. Datetime:   To calculate the time taken to complete the task of inserting the records into the database. Below is the snapshot of the CSV data saved as "Transaction_File" Transaction_File Below is the snapshot of the python code to insert each record to the server: In the above snap, the data is read and loaded to a data frame called df1,  and the blank values are filled with " NA " using the .fillna...