Menu

Build a cost-per-mile report for a truck from bank and card CSVs
📰

Build a cost-per-mile report for a truck from bank and card CSVs

DEV Community: datascience·Damin Mutti·15 days ago
#s3RntXqC
#devtodatascience#science#devto#dev#truck
Reading 0:00
15s threshold

Cost per mile is total operating cost for a period divided by the miles driven in that period. To get it from bank data you need four things: every transaction from the business bank account, card and fuel card for the month, a rule that puts each one in a cost bucket, the interest part of the truck payment (not the whole payment), and the month's miles from the ELD. Divide each bucket by the miles, add them up, and you have the number that tells a driver which loads lose money.

Here's a working version with pandas, and the mistakes that make most homemade versions wrong.

The inputs

Three CSVs for October 2026 for a fictional one-truck owner-operator, Pinecrest Hauling, plus one number from the ELD:

import pandas as pd from decimal import Decimal

MILES = 10_400 # ELD total for October 2026 frames = [] for path , source in [( " checking.csv " , " bank " ), ( " card.csv " , " card " ), ( " fuelcard.csv " , " fuel_card " )]: df = pd .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.