Posts

DAY 31 - Organize a Secret Santa Game in your organization using a Python Script

Image
 The script will  perform below mentioned activities: 1.      Assign a Secret Santa randomly to each participant 2.      Save the final extract into an excel file 3.      Send an automated mail to each Secret Santa with a complete address details of his/her Secret Santa Child   Sample final extract file: Sample Mail Format: Prerequisite: 1.       Collect information of participants in an excel file as shown below. 2.  Click on “Manage your Google Account” > Security > Less secure app access Turn ON access for less secure app Note - This setup is required to send a mail from Gmail using Python script   Python Script: # -*- coding: utf-8 -*- """ Created on Wed Dec 2 12:15:58 2020 @author: Rakesh.Ranjan """ import random import pandas as pd import numpy as np import os import string  ss_keys = [] ssc_values = [] input_file_name = "Secret Santa - Information needed-Tes...

Day 30 - Learn the concept of comprehension,lambda,map,filter,reduce via simple examples

Image
 # -*- coding: utf-8 -*- """ Created on Tue Sep  8 11:20:22 2020 @author: Rakesh.Ranjan """ def square(x):     return x**2   def even(x):     return x%2 == 0   numbers = [1,2,3,4]  #Comprehension #1. the expression inside the brackets first starts with the operation/output that you desire, and then loops and conditionals occur in the same order of the regular code.  lc_square = [numbers[i]**2 for i in range(len(numbers))] print('Comprehension example:',lc_square) #lambda  #lambda input parameter(s):operation/output  countries = ['India','Pakistan','Bhutan','Nepal','Bangladesh'] func_lambda = lambda x: x.lower() print('lambda example:',func_lambda('India')) #A. Map  #map(function,iterable object)  #1. The function here can be a lambda function or a function object.  #2. The iterable object can be a string, list, tuple, set or dictionary.  lm_map = map(square, numbers)   print('map exa...

Populate a MS Word Template Using Python Script

Image

Day 29 - Populate a MS Word template With a Python Script

Image

Day 28 - Play with MS-Word using Python Script

Image
Sometimes we have to scan the data from MS-Word so that we would  proceed with next set of activities. Here you go, buddy !!!! You can use this script to read the content of MS-word + Add a new paragraph in the doc + Add a new image in the doc Python Script: # -*- coding: utf-8 -*- """ Created on Tue Jun 16 18:43:01 2020 @author: Rakesh.Ranjan """ import docx import pandas as pd doc = docx.Document("C:\\Users\\Rakesh.Ranjan\\Desktop\\LND\\MS-DOC.docx") #reading 1st paragraph single_para = doc.paragraphs[0] print(single_para.text) line_number = 0 #Reading all Paragraphs all_paras = doc.paragraphs print(len(all_paras)) #creating an empty dataframe column_names = ["line_number","line_text"] doc_df = pd.DataFrame(columns = column_names) #reading each paragraph and storing it in the dataframe for para in all_paras:     doc_df = doc_df.append({"line_number":line_number, "line_tex...