Sub topic 9
Total the hours by category
This chapter assumes you have a cleaned seven-day log with no gaps or overlaps, a fixed set of categories, and basic comfort with spreadsheets. Python is optional. You will turn the rows of your log into one table: hours and share of time for each category.
Why totals come first
A log of 150 rows tells you very little by eye. Totals answer the guiding question of your audit, such as "Where does my focused time go?" They also give you a baseline. Later chapters compare planned and actual time, and look for patterns. Both need these numbers.
The calculation has three steps:
- Compute the duration of each row (end minus start).
- Add the durations for each category.
- Divide each category total by the grand total.
The log format
Here is a minimal log. Each row has a date, start and end times in 24-hour format, a category, a short note, and an energy rating from 1 to 5.
date,start,end,category,activity,energy
2026-03-02,09:00,10:30,deep_work,Draft quarterly report,4
2026-03-02,10:30,10:50,communication,Email and chat,3
2026-03-02,10:50,11:30,meetings,Team standup and follow-up,3
2026-03-02,11:30,12:15,admin,Expense reports,2Save it as time_log.csv. Keep the category names identical on every row. deep_work and Deep work count as two different categories in any tool.
Totals in a spreadsheet
Add a column named hours and use this formula in row 2, then fill it down:
=(C2-B2)*24Spreadsheets store times as fractions of a day, so you multiply by 24 to get hours. Then build a summary table with SUMIF, which sums the values in one column when another column matches a condition:
=SUMIF(D:D, "deep_work", G:G)Divide each result by the sum of all category totals to get the percentage.
Totals with Python
This script does the same work. It reads the CSV, adds up the hours for each category, and prints each category's hours and share, largest first.
import csv
from collections import defaultdict
from datetime import datetime
totals = defaultdict(float)
with open("time_log.csv", newline="") as f:
for row in csv.DictReader(f):
start = datetime.strptime(row["start"], "%H:%M")
end = datetime.strptime(row["end"], "%H:%M")
totals[row["category"]] += (end - start).total_seconds() / 3600
grand_total = sum(totals.values())
for category, hours in sorted(totals.items(), key=lambda item: item[1], reverse=True):
print(f"{category}: {hours:.1f} h ({hours / grand_total:.0%})")For the four sample rows, the output is:
deep_work: 1.5 h (47%)
meetings: 0.7 h (21%)
admin: 0.8 h (24%)
communication: 0.3 h (9%)Wait: that order is wrong, and the check is worth doing. Admin is 45 minutes (0.75 h) and meetings are 40 minutes (0.67 h), so admin ranks higher. The real output is:
deep_work: 1.5 h (47%)
admin: 0.8 h (23%)
meetings: 0.7 h (21%)
communication: 0.3 h (9%)Rounded percentages can add up to 99% or 101%. That is normal.
Checking your totals
Before you trust the numbers, run three checks:
- Sum check. The grand total should match the hours you meant to cover. If you logged 10 hours a day for 7 days, expect about 70 hours. A large shortfall means gaps your cleanup missed.
- Category check. Print the list of distinct categories. A stray spelling variant shows up as an unexpected extra line.
- Reasonableness check. If one category looks far too large or small, find its longest rows. One mistyped end time is a common cause.
Decide what the percentage means. A share of logged time is different from a share of the waking day. If you logged only working hours, say so in your summary, so you do not compare it with a figure that covers 16 hours.
Exercise
A log has three rows: research 09:00–10:30, email 10:30–11:00, research 14:00–15:00. What are the hours and percentage for research?
Show answer
Research is 1.5 h + 1 h = 2.5 h. The grand total is 2.5 h + 0.5 h = 3 h. Research is 2.5 / 3 = 83% of logged time.
Exercise
Why does the script give a wrong result for a row from 23:30 to 00:15, and how can you fix it?
Show answer
It subtracts times without dates, so 00:15 minus 23:30 is negative. Split the entry into two rows at midnight, or store full date-and-time values for start and end.