Welcome reader! Like our contract stacking article, we often get asked about Python automation. Next to that would be the SaaS affiliate material. Which is, in certain aspects, a great type of WiFi money - maybe we will drop an article. Believing it’s often kept hidden from the others on purpose. Those who know about it don’t want others to make money.
Regarding your 9-5, would you rather manually do all of your work or have a code do it for you? This is a straightforward way to start the article, but that’s why you are here. We all wonder how we could cut our work time shorter. The answer?
Python.
Do yourself a favor in case you start automating your daily activities. Under any circumstances, you should not present it in the way you are “freeing up your time” when it comes to your 9-5. Especially not to your work colleagues. Present it in a way you are overburdened and need something to help you get everything in check. Python helped you save two extra hours per day, so you are better off pretending you are doing something. Crucial if you are working in the office. Different story if you are working remotely. The idea here is not to present it as if you are doing this because you want more free time.
Importance Of Python
Not going into the Python basics since that’s something you should already know if you plan to automate your tasks. No one can deny that it’s easy to learn Python. The main reason is because it’s written so that kids can understand it. Which is perfect because everyone can use it to their advantage. If you have no prior coding experience, don’t be put off by looking at the code. It’s something that you build up the resistance to over time. Just like everything else in life.
Trust us on this everyone can do it.
It looks much harder than it is - without even mentioning that now you have all kinds of different AI services to help you create your scripts. What's great about Python is how much you can do with little input. Rarely does another programming language allow you that type of flexibility. Not to say there are no better options. However, we primarily needed the automation part in our 9-5, and Python was the perfect solution.
Workplace Python And You
Not all the roles will have the same opportunities to automate their tasks. Strictly talking about office work. There is not yet a Python script that can help you with manual labor. The industry is trying hard to invent them. Unfortunately, this is not good news if you work manual labor. It's far from it, but it's not something you should be worried about currently.
We are curious about how this will age.
Depending on your current role and daily activities,, you will have an easier or harder time getting things done with Python. If your work is done mostly in Excel, that’s a big plus. Since Python is great at taking care of spreadsheets. In case it’s more browser or specific application based. You will still be able to pull it off. But with more thinking and strategic code behind it. We will try our best to cover the parts the majority will benefit from - the rest is up to you.
Creating Priority List
Before doing any coding, automation, or Python scripting. The crucial step for you is to realize what daily activities you can automate. One of the easiest ways to put it would be to keep track of how you spend your daily time for a week or two. Those are the ones you should be attacking first. If you know you have an Excel report that takes 30 minutes of your time each day, automating it will leave you around 2 hours less work in a week.
It doesn’t take a rocket scientist to conclude that this should be your top priority.
Putting all your daily activities on paper or in an Excel sheet and thinking in terms of hours… Will make you realize how much of your life you are wasting on low ROI activities. In counter-argument, we all agree you are getting paid for those same activities. Questions is it worth it? The topic for another time. Maybe something that will help you understand you need WiFi income.
Creating a systematic approach is a way to go. Your first step should be attacking the biggest time wasters. An additional thing you could do when creating your priority list is add the application name next to it.
Why?
Not all applications require the same level of knowledge when it comes to automating tasks. The data is made up, and it doesn’t make sense that someone would refresh sales for 10 minutes. The example below should provide a general overview of how to build the list and prioritize based on it.
Python On Your Work Machine
Something we already covered in one of the earlier articles. When it comes to Python and your workplace. Everything comes down to how far you will be able to push things. Talking about company security and policies in your workplace. Security plays a huge role in each organization, and you will often have to request permissions from your IT department - depending on the company structure. If you are working as a coder or are already in the IT department, there should not be any problems.
Keep in mind you will have to prepare your "defense" and explain why you want it installed on the machine. Under any circumstance don’t mention you want more free time. Play smart and go for extra “work” that Python will allow you to do.
Nothing much more to add here except good luck getting Python on your machine. If you are extra brave ask for an IDE to help yourself with the code setup and changes since you will need it along the way - sooner or later, better said.
Tricking Your IT Department
The blueprint has already been given away, just like the information above. If you do not care and want to do things your way. One of the solutions would be to set yourself up with a USB with WinPython on it. This means you will be able to run Python on your USB stick. This gives you an option to exclude anyone from your IT department, ask for permission, and do everything your way. This is not legal advice - but it works. Remember, fortune favors bold.
Successfully Cutting Your Worktime
You have your list of priorities, and you have got Python working on your machine. Now the fun parts start. Unfortunately, it’s impossible to give you all the solutions, tricks, and logic behind them. You will have to do this once you get experience in Python automation.
Each individual will have a different approach to getting things done. If you put three individuals with the “same problem” and give them a code to solve it, there is a huge chance everyone will manage to achieve the "solution," but everyone will have a different way of doing it. What do we want to say?
Only you can develop a 100% solution that will fit your needs.
That is why we will not detail how to do specifics. But we are going to provide you with the bigger picture. It's up to you to do the rest of the work. We cover the "most used" applications and methods that could bring value. Anyway, most office jobs are boring and repetitive. Copy this, copy that throw it into Excel… Extra points if you are doing manual work with PDFs using CTRL+F to go through them.
It is worth mentioning that we are not sure about everyone's technical background. We doubt we have readers who have never used a macro in Excel - there is nothing wrong with that. That is why we will focus on “common” use cases where you could use Python automation to your advantage.
When it comes to being successful with Python automation. You have to think outside of the box. Meaning you will not only follow the examples given. But what you want to do instead is combine them all to your case. Once you gain more experience, you will realize there is no problem with getting data from web applications → running them in an Excel file → outputting reports as a PDFs file → sending PDFs over email. All should be done automatically without you performing any of the steps in the process. That’s how you save time.
Automating Excel
Excel activities are the biggest time waster for the big majority. Serving as a great starting point when it comes to automation. Pandas is one of the Python libraries you should get comfortable with regarding Excel. No doubt. Copying and appending data to existing files or creating completely new files... Would bet that almost everything related to Excel can be done with Pandas. In case you are doing SQL work, Pandas has that covered, too. Present a few simple ideas from which 90% of white-collar workers could benefit. Remember how you could scale them up to your specific case.
Excel helpers:
Copying cells from one file to another
import pandas as pd
# Locating the file you want to copy from
source_file = "" # Path to your source file
df_source = pd.read_csv(source_file)
# Read the target file (the file you want to overwrite cells in)
target_file = "" # Path to your target file
df_target = pd.read_csv(target_file)
# What you want to overwrite
row_indices = [2, 3] # Rows
column_names = ['A', 'C'] # Columns
# Copying target DataFrame to the source DataFrame
for row_idx in row_indices:
for col_name in column_names:
df_target.at[row_idx, col_name] = df_source.at[row_idx, col_name]
# Updated DataFrame to the target file
df_target.to_csv(target_file, index=False)
print("Cells overwritten successfully!")
Appending cells to the existing file
import pandas as pd
# Locating the file you want to copy from
source_file = "" # Path to your source file
df_source = pd.read_csv(source_file)
# DataFrame (read further on it - it is amazing) with selected cells
# We are copying cells from rows 2 and 3, and columns 'A' and 'C'
selected_data = df_source.loc[2:3, ['A', 'C']]
# Locating the target file
target_file = "" # Path to your target file
df_target = pd.read_csv(target_file)
# Append the selected data
df_target = df_target.append(selected_data, ignore_index=True)
# Updated DataFrame to the target file
df_target.to_csv(target_file, index=False)
# Confirmation
print("Cells copied successfully!"
Exporting Excel sheet to PDF
import pandas as pd
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
import datetime
# Excel file input
input_excel = "" # Path to your input file
# Sheet name to convert
sheet_name = "" # Replace with the name of the sheet you want to print out
# Reading specifics into DataFrame
df = pd.read_excel(input_excel, sheet_name=sheet_name)
# PDF function
current_date = datetime.datetime.now().strftime("%Y-%m-%d")
output_pdf = f"{sheet_name}_{current_date}.pdf"
# PDF output options
c = canvas.Canvas(output_pdf, pagesize=letter)
# Convert the DataFrame to a string representation (tabular format)
table_data = df.to_string()
# Writing out the data in PDF
c.drawString(50, 750, table_data) # Adjust the position as needed
# Saving PDF
c.save()
# Confirmation
print(f"{sheet_name} from {input_excel} converted to {output_pdf} successfully!")
If you are running a Windows machine, another great Python library worth checking out is win32com. This is not only for Excel but also for other Windows services. What is great about using win32com is that it’s one of the easiest ways to visually see what your code is doing - you will see a few examples further in the article. Not always the easiest when using other libraries since things are happening in the background… If you are running a Windows machine (majority), you should pay attention to this. Especially if you are new to Python automation and want to see how your codes affect certain applications.