Saturday, 5 April 2025

Python

Connecting to SQL databse and inseting the data using Python



# Azure SQL Database connection details
server = 'ServrerName'
database = 'DatabaseName'  # Replace with your database name
username = 'UserId'
password = 'Password'
driver = 'ODBC Driver 17 for SQL Server'

# Create the connection string
connection_string = f'mssql+pyodbc://{username}:{password}@{server}/{database}?driver={driver}'

# Create the SQLAlchemy engine
engine = create_engine(connection_string)

# Insert the data into the Azure SQL Database

partspec_insert.to_sql('Part', con=engine,schema='LSQ', if_exists='append', index=False)








Python

 Ranaming a column in data frame



Writing the Read data into Excel sheet

  • Here if_sheet_exists = 'replace' will overite the data in the sheet if the sheet exists already
import pandas as pd
#Data frame
partspec_insert=df[['PartId', 'PartRev', 'AddedBy']]
#Write the DataFrame to a new sheet in the same Excel file
with pd.ExcelWriter(file, engine='openpyxl', mode='a', if_sheet_exists = 'replace') as writer:
      partspec_insert.to_excel(writer, sheet_name='Processed Data', index=False)







Moving file to destination folder after processing


import os
import shutil
destination_folder_path=r'C:\Users\BK2\Desktop\Test Folder\Processed Files'
shutil.move(file, os.path.join(destination_folder_path, os.path.basename(file)))
Print('Files moved to Destination Folder')





Drop Duplicates from Dataframe






Friday, 4 April 2025

Power Bi

 Select Distinct of Part Number For 2 Dim Tables and make it Fact table