Posts

Fuzzywazzy in data science

 import numpy as np import pandas as pd from fuzzywuzzy import process import fuzzywuzzy df = pd.DataFrame({"name":["alice_sahu","alice sahu","banika_pradhan","banika pradhan,","banika pradhan","swapita_maheswari"],"age":[20,22,35,21,19,30]}) name = df['name'] unique_array = df['name'].unique() #print(unique_array) match_value = fuzzywuzzy.process.extract("alice_sahu",name,limit=10,scorer=fuzzywuzzy.fuzz.token_sort_ratio) #print(match_value) df['name'] = df['name'].str.strip(',') #print(df) close_matches = [] for match in match_value:      #for matches in match:   if match[1]==90:              close_matches.append(match[0]) print(close_matches) row_matches = df['name'].isin(close_matches) #name = df['name'] df.loc[row_matches,'name']=["alice_sahu"] print(df)   

Programming

 import pandas as pd # Load the Excel file into a DataFrame df = pd.read_excel("your_file.xlsx") # Split the header into multiple columns based on ';' header_split = df.columns[0].split(';') # Create a new DataFrame to store the split values split_values = pd.DataFrame(columns=header_split) # Iterate through each row and split the values after ';' for index, row in df.iterrows():     values = row[df.columns[0]].split(';')     # Pad the split values if there are fewer values than columns     if len(values) < len(header_split):         values += [''] * (len(header_split) - len(values))     split_values.loc[index] = values # Concatenate the split_values DataFrame with the original DataFrame df = pd.concat([df, split_values], axis=1) # Drop the original column containing the combined header and values df.drop(columns=[df.columns[0]], inplace=True) # Display the DataFrame print(df)

Email

 import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText def send_email(subject, body, to_email):     # Set up SMTP server credentials     smtp_server = 'smtp.gmail.com'     smtp_port = 587     smtp_username = 'laxminarayanarath5@gmail.com'     smtp_password = 'laxhackcreate105@LH'     # Create message container     msg = MIMEMultipart()     msg['From'] = smtp_username     msg['To'] = to_email     msg['Subject'] = subject     msg.attach(MIMEText(body, 'plain'))     # Connect to SMTP server and send email     with smtplib.SMTP(smtp_server, smtp_port) as server:         server.starttls()         server.login(smtp_username, smtp_password)         server.sendmail(smtp_username, to_email, msg.as_string()) # Example usage: if __name__ == "__main__":   ...

Pdf to docx

 from pdf2docx import Converter def convert_pdf_to_docx(pdf_path, output_docx):     cv = Converter(pdf_path)     cv.convert(output_docx, start=0, end=None)     cv.close()     print(f"Conversion successful: {pdf_path} to {output_docx}") # Replace 'input.pdf' with the path to your PDF file input_pdf = 'path/to/your/input.pdf' # Replace 'output.docx' with the desired output DOCX filename output_docx = 'path/to/your/output.docx' # Convert PDF to DOCX convert_pdf_to_docx(input_pdf, output_docx)

card slot machine

import random dict = {'A':4,'KING':4,'QUEEN':4, 'J':4, '10':4, '9':4, '8':4,'7':4,'6':4,'5':4,'4':4,'3':4,'2':4} ROWS = 3 COLS = 3 NUM_TIMES = 5 MAX_BET = 500  def sequence_game(alhp):     all_cards = []     for i, dict in alhp.items():         for _ in range(dict):             all_cards.append(i)     return all_cards         def deposit():   while True:     amount_input = input("how much amount you want to deposit? $ ")     amount = 0     if amount_input.isdigit():       amount = int(amount_input)       if amount > 0:         break       else:         print("amount must be greater than 0")   return amount def get_bet_amount():     while True:      bet_amount_input = (input("how much amount you want to bet ? $ "))     ...

sequence card game

  import random dict = { 'A' : 4 , 'KING' : 4 , 'QUEEN' : 4 , 'J' : 4 , '10' : 4 , '9' : 4 , '8' : 4 , '7' : 4 , '6' : 4 , '5' : 4 , '4' : 4 , '3' : 4 , '2' : 4 } ROWS = 3 COLS = 3 def sequence_game ( alhp , rows , cols ):     all_cards = []     for i , dict in alhp .items():         for _ in range ( dict ):             all_cards . append ( i )     user_input = input ( "do you want to play ? " )     if user_input == 'y' :         print ( f "all_cards : { all_cards } " )     while True :             bet_amount_input = ( input ( "how much amount you want to bet ? $ " ))       bet_amount = 0                   if bet_amount_input . isdigit ():       bet_amount = int ( bet_amount_input )       if bet_amount > 0 : ...

Card Game In Python

 import random dict = {'A':4,'KING':4,'QUEEN':4, 'J':4} ROWS = 3 COLS = 3 def sequence_game(alhp,rows,cols):     all_cards = []     for i, dict in alhp.items():         for _ in range(dict):             all_cards.append(i)     user_input = input("do you want to play ? ")     if user_input == 'y':         print(f"all_cards : {all_cards}")     random_choice = []          for col in range(cols):      value = random.choice(all_cards)      all_cards.remove(value)      random_choice.append(value)                        lets_distribute_all_cards = input(" ready to distribute ? ")     if lets_distribute_all_cards == 'y':                           print(random_c...