Skip to content

As electronic vehicles (EVs) become more popular, there is an increasing need for access to charging stations, also known as ports. To that end, many modern apartment buildings have begun retrofitting their parking garages to include shared charging stations. A charging station is shared if it is accessible by anyone in the building.

But with increasing demand comes competition for these ports — nothing is more frustrating than coming home to find no charging stations available! In this project, you will use a dataset to help apartment building managers better understand their tenants’ EV charging habits.

The data has been loaded into a PostgreSQL database with a table named charging_sessions with the following columns:

charging_sessions

ColumnDefinitionData type
garage_idIdentifier for the garage/buildingVARCHAR
user_idIdentifier for the individual userVARCHAR
user_typeIndicating whether the station is Shared or PrivateVARCHAR
start_pluginThe date and time the session startedDATETIME
start_plugin_hourThe hour (in military time) that the session startedNUMERIC
end_plugoutThe date and time the session endedDATETIME
end_plugout_hourThe hour (in military time) that the session endedNUMERIC
duration_hoursThe length of the session, in hoursNUMERIC
el_kwhAmount of electricity used (in Kilowatt hours)NUMERIC
month_pluginThe month that the session startedVARCHAR
weekdays_pluginThe day of the week that the session startedVARCHAR

Let’s get started!

Sources
  • Data: CC BY 4.0, via Kaggle,
  • Image: Julian Herzog, CC BY 4.0, via Wikimedia Commons

Find the number of unique individuals that use each garage’s shared charging stations.

The output should contain two columns: garage_id and num_unique_users. Sort your results by the number of unique users from highest to lowest. Save the result as unique_users_per_garage.

Spinner
DataFrameas
unique_users_per_garage
variable
-- unique_users_per_garage
SELECT garage_id, COUNT(DISTINCT user_id) AS num_unique_users
FROM charging_sessions
WHERE user_type = 'Shared'
GROUP BY garage_id
ORDER BY num_unique_users DESC;
Hidden output
indexgarage_idnum_unique_users
0Bl218
1AsO217
2UT916
3AdO33
4MS12
5SR22
6AdA11
7Ris1

Find the top 10 most popular charging start times (by weekday and start hour) for sessions that use shared charging stations.

Your result should contain three columns: weekdays_plugin, start_plugin_hour, and a column named num_charging_sessions containing the number of plugins on that weekday at that hour. Sort your results from the most to the least number of sessions. Save the result as most_popular_shared_start_times.

Spinner
DataFrameas
most_popular_shared_start_times
variable
-- most_popular_shared_start_times
SELECT weekdays_plugin, start_plugin_hour, COUNT(*) AS num_charging_sessions
FROM charging_sessions
WHERE user_type = 'Shared'
GROUP BY weekdays_plugin, start_plugin_hour
ORDER BY num_charging_sessions DESC
LIMIT 10;
Hidden output
indexweekdays_pluginstart_plugin_hournum_charging_sessions
0Sunday1730
1Friday1528
2Thursday1926
3Thursday1626
4Wednesday1925
5Sunday1825
6Sunday1525
7Monday1524
8Friday1624
9Tuesday1623

Find the users whose average charging duration last longer than 10 hours when using shared charging stations.

Your result should contain two columns: user_id and avg_charging_duration. Sort your result from highest to lowest average charging duration. Save the result as long_duration_shared_users.

Spinner
DataFrameas
long_duration_shared_users
variable
-- long_duration_shared_users
SELECT user_id, AVG(duration_hours) AS avg_charging_duration
FROM charging_sessions
WHERE user_type = 'Shared'
GROUP BY user_id
HAVING AVG(duration_hours) > 10 
ORDER BY avg_charging_duration DESC
Hidden output
indexuser_idavg_charging_duration
0Share-916.845833335
1Share-1712.8945555511
2Share-2512.2144747466
3Share-1812.0888071898
4Share-811.5504308392
5AdO3-110.3693869729