%matplotlib inline
import pandas as pd
trajets = pd.read_hdf('../datachallenge/divvy-trips.h5', 'fixed')
Afficher les statistiques sur la durée
trajets.tripduration.describe()
count 1548935.000000 mean 996.651052 std 1746.803926 min 60.000000 25% 422.000000 50% 724.000000 75% 1200.000000 max 86392.000000 dtype: float64
Les mêmes, mais en minutes
(trajets.tripduration / 60).describe()
count 1548935.000000 mean 16.610851 std 29.113399 min 1.000000 25% 7.033333 50% 12.066667 75% 20.000000 max 1439.866667 dtype: float64
Abonnés vs occasionnels
Attention! sum()
n'est pas la même chose que count()
. Ici on veut compter le nombre de lignes (peu importe quelle colonne).
trajets.groupby('usertype').count().trip_id.plot(kind='bar')
<matplotlib.axes._subplots.AxesSubplot at 0x7faaba1c8350>
# Une solution alternative
trajets.usertype.value_counts().plot(kind='bar')
<matplotlib.axes._subplots.AxesSubplot at 0x7faaba152310>
Age maximum et minimum
(2014 - trajets.birthyear).describe()
count 1071696.000000 mean 35.155730 std 10.476417 min 16.000000 25% 27.000000 50% 32.000000 75% 41.000000 max 116.000000 dtype: float64
Distribution des sexes.
Mêmes remarques qu'avant.
trajets.groupby('gender').count().trip_id.plot(kind='pie')
<matplotlib.axes._subplots.AxesSubplot at 0x7faaba12f690>
Trajets en fonction de l'age.
Encore une fois, on veut compter, pas sommer !
trajets.groupby(2014 - trajets.birthyear).count().trip_id.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7faab97d0350>
trajets.set_index('starttime', inplace=True, drop=False)
trajets['date'] = trajets.index.date
trajets['joursemaine'] = trajets.index.weekday
trajets['heure'] = trajets.index.hour
Durée moyenne par jour (calendrier).
On ne veut plus compter : on veut une moyenne (mean)
trajets.groupby('date').mean().tripduration.plot()
<matplotlib.axes._subplots.AxesSubplot at 0x7faab3f6b2d0>
trajets.groupby('joursemaine').mean().tripduration.plot(kind='bar')
<matplotlib.axes._subplots.AxesSubplot at 0x7faab9626550>