Quick summary analysis of driving habits with the Automatic tracker for past 13 months.
Written: 08-02-2017

Intro:

I realized last night that I have had my 2004 Volvo Wagon for over a year now. It’s not exactly a car I love, mostly because it has some issues, which I knew about when I bought it. I do love driving Volvo wagon’s though, especially as something to roll around town in. I added the Automatic tracker to the car when I bought it, primarily so I could see all the engine warning codes and know when I needed to take it to Robert at Meadowthorpe Motors (the reason I buy Volvo’s), or when I could ignore them.

Knowing I had a year’s worth of data available, I decided to go pull down the data and do a quick analysis of my driving habits. Here’s a quick look:

Interesting observations:

  • I had 1,861 trips!  This seems ridiculously high, until you realize that every time you go out to a store you’ll make a minimum of 2 trips and often many more. I’m assuming this will be less this year, now that I commute most place on bike?
  • The month I drove the most miles was May 2017… which is the month I moved.
  •  When I leave town in a car, I always rent a car. So in February when I drove to Kansas and Texas, along with Minnesota in June are not reflected in mileage driven.
  • Moving has decreased the total driving, on average.
  • I don’t really spend that much on gas. Only one month (again May 2017) did I spend more than $100 on gas.

The analysis (completed using a Jupyter Notebook):

Import pandas, numpy and read in data from csv exported from Automatic

In [46]:
import pandas as pd
In [47]:
import numpy as np
In [48]:
trip = pd.read_csv('automatic-trips-2017-08-01.csv')

Pull out the first two rows from data frame to see what is available

 

Here you can see my trip from Joseph Beth Bookstore to Barnes & Noble, than B&N to Five Guys !!

Here’s an image capture of that output:
Screenshot 2017-08-02 08.36.43

Create a dataframe with only the columns of data initially interested in, then print the head to view

In [50]:
trip[['Vehicle','Start Time', 'Distance (mi)', 'Fuel Cost (USD)']].head()
Out[50]:
Vehicle Start Time Distance (mi) Fuel Cost (USD)
0 2004 Volvo V70 2017-08-01 8:03 PM 1.73 0.21
1 2004 Volvo V70 2017-08-01 7:24 PM 9.04 0.81
2 2004 Volvo V70 2017-08-01 7:00 PM 4.98 0.53
3 2004 Volvo V70 2017-07-31 7:35 PM 2.17 0.28
4 2004 Volvo V70 2017-07-31 7:10 PM 9.90 1.00

The date needs to be changed to datetime format, but checking current type first

In [51]:
type(trip['Start Time'][0])
Out[51]:
str
In [52]:
trip.loc[:, 'Start Time'] = pd.to_datetime(pd.Series(trip['Start Time']))
In [53]:
type(trip['Start Time'][0])
Out[53]:
pandas._libs.tslib.Timestamp

I want to use the TimeGrouper method from pandas, so need to set index to the datetime

In [54]:
trip.set_index(trip['Start Time'], inplace=True)

Print first 5 rows to make sure index is now set to ‘Start Time’

In [58]:
trip[:2]
Here’s an image capture of that output:
Screenshot 2017-08-02 08.36.43

Some columns no longer makes sense after applying sumer (avg. mpg, etc), subsetting desired columns for new dataframe

In [57]:
monthly_miles[['Distance (mi)', 'Duration (min)', 'Fuel Cost (USD)', 'Fuel Volume (gal)', 'Hard Brakes', 'Hard Accelerations']]
Out[57]:
Distance (mi) Duration (min) Fuel Cost (USD) Fuel Volume (gal) Hard Brakes Hard Accelerations
Start Time
2016-07-31 497.85 1265.68 49.51 20.85 19 0
2016-08-31 692.04 2217.81 77.31 32.84 47 9
2016-09-30 825.78 2396.94 85.45 36.00 40 3
2016-10-31 792.81 2148.12 82.74 32.75 27 2
2016-11-30 662.76 2000.36 69.73 29.27 15 0
2016-12-31 704.19 2273.12 83.56 33.14 23 0
2017-01-31 555.44 1731.53 65.27 25.12 6 1
2017-02-28 453.55 1290.42 47.37 19.22 14 2
2017-03-31 723.20 2151.33 76.75 31.01 19 5
2017-04-30 797.27 2331.63 81.87 31.47 20 0
2017-05-31 943.92 2899.84 103.62 38.95 49 0
2017-06-30 256.22 821.56 26.54 10.38 12 0
2017-07-31 400.41 1347.42 44.46 17.40 15 0
2017-08-31 15.75 36.01 1.55 0.61 0 0
In [ ]: