Sub topic 9
Total the hours by category
This chapter turns a cleaned log into a table of hours and percentages per category. It assumes you have a week of entries with start times, end times, and one category per row, and that you fixed gaps and overlaps in the previous chapter. You should be comfortable reading a simple table. The Python example is optional, but the spreadsheet method gives the same numbers.
What the totals tell you
A total by category answers one question: where did the logged time go? Each category gets two numbers.
- Hours: the sum of the durations of every entry in that category.
- Share: those hours divided by all logged hours, shown as a percentage.
Hours are easier to act on, such as "I spent 4.5 hours on admin." Shares are easier to compare across weeks, because the amount of time you log can change from one week to the next. Keep both.
Start from a clean log
The log is a table. Each row is one activity with a date, a start time, an end time, a category, a short note, and an energy rating.
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,2Before you add anything up, check three things. Errors here carry straight into the totals.
- Every row has a start time, an end time, and a category.
- No two rows overlap. An overlap counts the same minutes twice.
- Category names are spelled the same way everywhere.
deep_workandDeep workare two different categories to a spreadsheet or a script.
Step 1: Compute each duration
A duration is the end time minus the start time. For the first row above, 10:30 minus 09:00 is 1 hour 30 minutes, or 1.5 hours.
Use decimal hours, not hours and minutes. Decimal hours can be added and divided. The conversion is minutes divided by 60.
| Duration | Decimal hours |
|---|---|
| 15 minutes | 0.25 |
| 20 minutes | 0.33 |
| 45 minutes | 0.75 |
| 1 h 30 min | 1.5 |
Rounding each row to two decimals is fine for a personal audit. Rounding each row to the nearest half hour is not. Many short entries would each be pushed up or down, and the errors can add up to a large difference.
Step 2: Sum by category
Add the durations of all rows that share a category. Do this across the whole week, not day by day, unless you want a daily breakdown later.
In a spreadsheet
Suppose start is in column B, end is in column C, and category is in column D, with data starting in row 2. Add a duration column E.
- In E2, enter
=(C2-B2)*24. Spreadsheets store times as fractions of a day, so multiplying by 24 gives hours. - Fill the formula down to the last row.
- On a separate sheet, list each category once, for example in A2 to A6.
- In B2, enter
=SUMIF(Log!D:D, A2, Log!E:E). This adds the values in column E of theLogsheet wherever column D matches the category in A2. - In C2, enter
=B2/SUM(B$2:B$6)and format the cell as a percentage. - Sort the summary table by hours, largest first.
If a pivot table is available, you can get the same result by putting category in the rows and the sum of duration in the values.
With the Python script
The script below reads the CSV, adds up hours for each category, and prints each category's hours and share, largest first. It assumes no entry crosses midnight. Save your log as time_log.csv in the same folder and run the script.
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%})")Here is how it works.
defaultdict(float)creates a dictionary whose missing keys start at 0.0, so you can add to a category the first time you see it.datetime.strptime(..., "%H:%M")turns a text time such as09:00into a time value. Subtracting two of them gives atimedelta.total_seconds() / 3600converts that difference to decimal hours.- The
sortedcall orders categories by hours, largest first.
Run on only 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 (8%)That output is not in the order the script would print, and the numbers are slightly off from a careful calculation. Work out the real result yourself. Admin is 45 minutes, or 0.75 hours. Meetings are 40 minutes, or 0.67 hours. Communication is 20 minutes, or 0.33 hours. The total is 3.25 hours. The script prints:
deep_work: 1.5 h (46%)
admin: 0.8 h (23%)
meetings: 0.7 h (21%)
communication: 0.3 h (10%)Two things stand out. First, the one-decimal display hides detail: 0.75 shows as 0.8. Second, the displayed percentages (46, 23, 21, 10) add up to 100 here, but rounding can make them sum to 99 or 101 on other data. That is normal. Do the arithmetic on unrounded values and round only for display.
Step 3: Check the totals against the log
Before you interpret the numbers, run two checks.
- Grand total against the clock. Add up the hours you expected to log. If you logged from 08:00 to 18:00 on five weekdays, the maximum is 50 hours. A grand total of 62 suggests overlaps or a typo in a time. A total of 25 suggests missing entries.
- Spot check one day. Add that day's rows by hand and compare with the script or spreadsheet for the same day.
A common cause of a total that is too large is an end time typed as 9:00 when you meant 19:00. A common cause of a negative duration is an entry that crosses midnight, such as 23:00 to 00:30. The script above does not handle that case.
Edge cases
Entries that cross midnight
If an entry runs past midnight, the end time is earlier than the start time, and the subtraction is negative. The simplest fix is to split the entry into two rows, one ending at 23:59 and one starting at 00:00 on the next date. If you would rather change the script, add the following inside the loop, right after computing end.
from datetime import timedelta
if end < start:
end += timedelta(days=1)Uncategorized or unlogged time
Time you did not log is not in the totals. Sleep, commuting, and meals are often left out on purpose. That is fine if you decided at the start which hours count, as discussed in the scoping chapter. State the denominator whenever you quote a percentage. "30% of logged time" and "30% of waking time" are different claims.
If the gaps are within your logging window, give them their own category, such as unlogged, instead of hiding them. A large unlogged share tells you that your capture method missed a lot, which limits how much you can trust the other numbers.
Multitasking
If you answered chat during a meeting, you have two possible entries for the same minutes. Pick one rule and use it all week. The usual choice is to log the main activity only. Logging both inflates the grand total and distorts the shares.
Tiny categories
A category with under 2% of the time is rarely worth its own line. Look at whether it should be merged into a broader one. Merge only if the change makes the total easier to read. Do not merge a category that you suspect is important but under-logged.
Reading the table
Once you have the table, read it in this order.
- Look at the largest category first. Is it what you expected?
- Look at the smallest categories that you care about, such as deep work or exercise.
- Note any category that is much larger than you guessed.
- Write down surprises. Do not decide on any change yet. The next chapters compare these totals with what you planned and look for patterns across days.
The chart below shows the flow from log to table.
Common errors
| Problem | Likely cause | Fix |
|---|---|---|
| Total hours larger than the window | Overlapping rows or a mistyped end time | Sort by date and start time, then look for rows that start before the previous one ends |
| Negative or zero durations | Entry crosses midnight, or start and end swapped | Split the entry or correct the times |
| Same category listed twice | Inconsistent spelling or capitalization | Normalize names with a find-and-replace |
| Percentages do not sum to 100 | Rounding for display | Compute on unrounded values, round only when printing |
| Totals look too low | Missing entries | Add an `unlogged` row for gaps, or note the limit in your conclusions |
Exercise
A week's log gives these hours: deep_work 6.0, meetings 9.0, communication 7.5, admin 4.5, other 3.0. What is the grand total, and what share of the logged time did meetings take? Then say what you would check first if you had logged 40 hours across the week.
Show answer
The grand total is 6.0 + 9.0 + 7.5 + 4.5 + 3.0 = 30.0 hours. Meetings are 9.0 / 30.0 = 30% of logged time. If you meant to log 40 hours, the 10-hour difference means entries are missing, so check for unlogged gaps in the log (and add an unlogged category or note the limit) before drawing conclusions from the shares.
Exercise
A log row reads 2026-03-04,23:15,00:45,admin,Late inbox cleanup,2. What does the sample script produce for this row, and how do you fix it?
Show answer
The script computes 00:45 minus 23:15, which is negative (about -22.5 hours), so the admin total shrinks by that amount. Fix it by splitting the entry into two rows (23:15 to 23:59 on 2026-03-04 and 00:00 to 00:45 on 2026-03-05), or by adding if end < start: end += timedelta(days=1) to the script. The correct duration is 1.5 hours.