HI All,
In this video we have below Question:
We need to connect our Python With SQL using Pyodbc library. After connecting we need to extract one data from SQL into python then we have to summarize that dat as per the requirement. After summarizing the data we need to export that summarization in any specific folder.
Required library : import Pyodbc & import pandas
Solution :
import pyodbc
import pandas as pd
Connection_String=pyodbc.connect('Driver={SQL Server};server=DESKTOP-V76UGV0;database=Python_data;trusted_connection=Yes')
Data_from_SQL= pd.read_sql("Select * from sheet3",Connection_String)
print(Data_from_SQL)
Summary_Data = pd.crosstab(Data_from_SQL['Agent'],Data_from_SQL['AcctType'],
Data_from_SQL['Amount'],aggfunc='sum',margins=True,margins_name='Total_Earning')
Masterdata=pd.DataFrame(Summary_Data)
Masterdata.to_excel('Python_Data_Summary.xlsx',sheet_name='Summary Sheet')
:
Apart from that if you want me to make video on any topic please let me know in comment box.
Download
0 formats
No download links available.
How we can connect Python with SQL in just few lines of code. | NatokHD