5 Office Tasks You Can Automate With Python
If you repeat the same steps every week, Python can probably do them for you. Here are five common office tasks and the idea behind automating each.
1. Rename files in bulk
Instead of renaming hundreds of photos or scans by hand, loop through the folder.
from pathlib import Path
for i, f in enumerate(sorted(Path("photos").glob("*.jpg")), start=1):
f.rename(f.with_name(f"event_{i:03d}.jpg"))2. Merge many Excel files
Monthly files with the same columns can be combined into one workbook with pandas.
import glob
import pandas as pd
files = glob.glob("monthly/*.xlsx")
df = pd.concat([pd.read_excel(f) for f in files], ignore_index=True)
df.to_excel("all_months.xlsx", index=False)3. Clean messy data
Remove duplicate rows and fix extra spaces and inconsistent capital letters.
df = df.drop_duplicates()
df["Name"] = df["Name"].str.strip().str.title()4. Summarise sales by region
summary = df.groupby("Region")["Revenue"].sum().sort_values(ascending=False)
summary.to_excel("region_summary.xlsx")5. Send reminder emails
Python's built-in smtplib and email modules can send messages from a list, such as fee or class reminders. Test with your own address first, and never store passwords inside your script.
How to start
- Pick one task you repeat every week.
- Write the steps in plain words first.
- Turn each step into a few lines of code.
- Test on copies of your files, not the originals.
Learn Python Programming in Bhubaneswar
Python for beginners: logic, data structures, files, automation and data basics. Classroom training at Chakeisiani, with a free demo class.
