Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

In dit labo maken we een verkennende analyse van open data van Uber. Terloops maken we kennis met de Pandas en Plotly bibliotheken.

Bron: Uber Data Analytics Dashboard

โœ… Data loaded successfully!

We hebben de data nu ingeladen als een Pandas DafaFrame (denk: Excel sheet ๐Ÿซฃ)

DataFrame

We kunnen snel de eerste of laatste rijen van de DataFrame bekijken via .head() en .tail.

Loading...
Loading...

We kunnen snel een idee krijgen van het aantal rijen via len()

๐Ÿ“ˆ Total rides: 150,000

Zoals bij NumPy, is er ook een .shape methode, maar die genereert enkel 2 dimensionele tuples.

๐Ÿ“Š Dataset shape: (150000, 21)
 - rows: 150,000
 - columns: 21

Kolomnamen zijn beschikbaar als een speciaal Index object via .columns

Index(['Date', 'Time', 'Booking ID', 'Booking Status', 'Customer ID', 'Vehicle Type', 'Pickup Location', 'Drop Location', 'Avg VTAT', 'Avg CTAT', 'Cancelled Rides by Customer', 'Reason for cancelling by Customer', 'Cancelled Rides by Driver', 'Driver Cancellation Reason', 'Incomplete Rides', 'Incomplete Rides Reason', 'Booking Value', 'Ride Distance', 'Driver Ratings', 'Customer Rating', 'Payment Method'], dtype='object')

De .info() methode geeft een nuttig overzicht van de kolommen en data types.
Merk op dat er voor sommige variabelen ontbrekende (niet-geregistreerde) waarden zijn (zogeheten missing values; zie Non-Null Count < 15000; bv. Customer Rating).

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 150000 entries, 0 to 149999
Data columns (total 21 columns):
 #   Column                             Non-Null Count   Dtype  
---  ------                             --------------   -----  
 0   Date                               150000 non-null  object 
 1   Time                               150000 non-null  object 
 2   Booking ID                         150000 non-null  object 
 3   Booking Status                     150000 non-null  object 
 4   Customer ID                        150000 non-null  object 
 5   Vehicle Type                       150000 non-null  object 
 6   Pickup Location                    150000 non-null  object 
 7   Drop Location                      150000 non-null  object 
 8   Avg VTAT                           139500 non-null  float64
 9   Avg CTAT                           102000 non-null  float64
 10  Cancelled Rides by Customer        10500 non-null   float64
 11  Reason for cancelling by Customer  10500 non-null   object 
 12  Cancelled Rides by Driver          27000 non-null   float64
 13  Driver Cancellation Reason         27000 non-null   object 
 14  Incomplete Rides                   9000 non-null    float64
 15  Incomplete Rides Reason            9000 non-null    object 
 16  Booking Value                      102000 non-null  float64
 17  Ride Distance                      102000 non-null  float64
 18  Driver Ratings                     93000 non-null   float64
 19  Customer Rating                    93000 non-null   float64
 20  Payment Method                     102000 non-null  object 
dtypes: float64(9), object(12)
memory usage: 24.0+ MB

Niet alle waarden zijn numeriek (bv. Time, Vehicle Type, Pickup Location)

Loading...

Via de .describe() methode krijgen we snel een overzicht van de centrale tendensen.

Loading...

Zoals in NumPy kunnen we een simpele transpose aanroepen.

Loading...

Iedere kolom kan apart als een Series object aangeroepen worden.

0 12:29:38 1 18:01:39 2 08:56:10 3 17:17:25 4 22:08:00 ... 149995 19:34:01 149996 15:55:09 149997 10:55:15 149998 07:53:34 149999 15:38:03 Name: Time, Length: 150000, dtype: object
'Series'
0 No Driver Found 1 Incomplete 2 Completed 3 Completed 4 Completed ... 149995 Completed 149996 Completed 149997 Completed 149998 Completed 149999 Completed Name: Booking Status, Length: 150000, dtype: object

Iedere Series is onderliggend een gewone NumPy array. Die kan je op elk moment oproepen via .values

array(['12:29:38', '18:01:39', '08:56:10', ..., '10:55:15', '07:53:34', '15:38:03'], shape=(150000,), dtype=object)
'ndarray'

Meer complexe indexering kan via .loc en .iloc syntax.

0 False 1 False 2 False 3 False 4 False ... 149995 False 149996 False 149997 False 149998 False 149999 False Name: Vehicle Type, Length: 150000, dtype: bool
Loading...
Loading...
Loading...
Loading...

We kunnen op verschillende manieren data aggregeren. Zie documentatie voor meer info.

Loading...

Het resultaat is telkens terug een DataFrame of Series.

Date 0 Time 0 Booking ID 0 Booking Status 0 Customer ID 0 Vehicle Type 0 Pickup Location 0 Drop Location 0 Avg VTAT 10500 Avg CTAT 48000 Cancelled Rides by Customer 139500 Reason for cancelling by Customer 139500 Cancelled Rides by Driver 123000 Driver Cancellation Reason 123000 Incomplete Rides 141000 Incomplete Rides Reason 141000 Booking Value 48000 Ride Distance 48000 Driver Ratings 57000 Customer Rating 57000 Payment Method 48000 dtype: int64
'Series'
Index(['Date', 'Time', 'Booking ID', 'Booking Status', 'Customer ID', 'Vehicle Type', 'Pickup Location', 'Drop Location', 'Avg VTAT', 'Avg CTAT', 'Cancelled Rides by Customer', 'Reason for cancelling by Customer', 'Cancelled Rides by Driver', 'Driver Cancellation Reason', 'Incomplete Rides', 'Incomplete Rides Reason', 'Booking Value', 'Ride Distance', 'Driver Ratings', 'Customer Rating', 'Payment Method'], dtype='object')
np.int64(57000)

We kunnen gebruik maken van ingebouwde visualisatiemogelijkheden...

<Figure size 640x480 with 1 Axes>

of onze eigen (rijkere) visualisaties maken met Plotly voor exploratieve data analyse (EDA).

Loading...
Loading...
Loading...

Analyse van Avg CTAT: Average trip duration from pickup to destination (in minutes)

Loading...

Dit is duidelijk niet zo informatief ... wat missen we?

  1. Eenduidige timestamps (datum + tijd)

Loading...
0 2024-03-23 12:29:38 1 2024-11-29 18:01:39 2 2024-08-23 08:56:10 3 2024-10-21 17:17:25 4 2024-09-16 22:08:00 ... 149995 2024-11-11 19:34:01 149996 2024-11-24 15:55:09 149997 2024-09-18 10:55:15 149998 2024-10-05 07:53:34 149999 2024-03-10 15:38:03 Length: 150000, dtype: object
0 2024-03-23 12:29:38 1 2024-11-29 18:01:39 2 2024-08-23 08:56:10 3 2024-10-21 17:17:25 4 2024-09-16 22:08:00 Name: DateTime, dtype: datetime64[ns]
Loading...
  1. Resampling en aggregatie per uur

Loading...
Loading...
  1. Subplots en smoothing

Loading...
  1. Aggregatie per uur van de dag

Loading...
Loading...
Loading...

Idem, maar per dag van de week.

Loading...

We bekijken de verdeling van de Booking Status

Loading...

Per type voertuig

Loading...

Correlaties

Loading...
Loading...