Skip to content
Project: Analyzing Electric Vehicle Charging Habits
The data has been loaded into a PostgreSQL database with a table named charging_sessions with the following columns:
Charging_sessions
| Column | Definition | Data type | 
|---|---|---|
| garage_id | Identifier for the garage/building | VARCHAR | 
| user_id | Identifier for the individual user | VARCHAR | 
| user_type | Indicating whether the station is SharedorPrivate | VARCHAR | 
| start_plugin | The date and time the session started | DATETIME | 
| start_plugin_hour | The hour (in military time) that the session started | NUMERIC | 
| end_plugout | The date and time the session ended | DATETIME | 
| end_plugout_hour | The hour (in military time) that the session ended | NUMERIC | 
| duration_hours | The length of the session, in hours | NUMERIC | 
| el_kwh | Amount of electricity used (in Kilowatt hours) | NUMERIC | 
| month_plugin | The month that the session started | VARCHAR | 
| weekdays_plugin | The day of the week that the session started | VARCHAR | 
Let’s get started!
To determine the number of unique individuals using each garage’s shared charging stations, we must complete the following steps:
- Retrieve Data: Extract data from the charging_sessions table.
- Filter Data: The data is filtered to include only rows where user_type is ‘Shared’
- Group by Garage: Group the data by garage_id, creating a set of rows for each unique garage_id.
- Select and Count: For each group, select the garage_id and count the number of unique user_id values.
- Sort Results: Sort the resulting groups by the count of unique user_id values, from highest to lowest.
DataFrameas
unique_users_per_garage
variable
-- unique_users_per_garage
-- Modify the code below
SELECT garage_id, COUNT(DISTINCT(user_id)) AS num_unique_users
FROM charging_sessions
WHERE user_type = 'Shared'
GROUP BY garage_id
ORDER BY COUNT(DISTINCT(user_id)) DESC;To identify the top 10 most popular charging start times by weekday and start hour, we follow these steps:
- Retrieve Data: Extract records from the charging_sessions table.
- Filter Data: The data is filtered to include only rows where user_type is ‘Shared’
- Group Records: Group the data by weekdays_plugin and start_plugin_hour.
- Select and Count: For each group, select the weekdays_plugin, start_plugin_hour, and count the number of unique user_id values.
- Sort Results: Order the results by the count of unique user_id values in descending order.
- Limit Output: Limit the output to the top 10 entries.
DataFrameas
most_popular_shared_start_times
variable
-- most_popular_shared_start_times
SELECT weekdays_plugin, start_plugin_hour, COUNT(user_id) AS num_charging_sessions
FROM charging_sessions
WHERE user_type = 'Shared'
GROUP BY weekdays_plugin, start_plugin_hour
ORDER BY COUNT(user_id) desc
LIMIT 10;
To identify users whose average charging duration exceeds 10 hours at shared charging stations, we follow these steps:
- Retrieve Data: Extract records from the charging_sessions table.
- Filter Data Pt. 1: The data is filtered to include only rows where user_type is ‘Shared’
- Group by User: Group the data by user_id.
- Filter Data Pt. 2: Restrict the query to include only those groups where the avg_duration_hours is greater than 10.
- SELECT: For each group, the user_id is selected, and the average duration_hours is calculated.
- Sort Results: Order the results by average duration_hours in descending order.
DataFrameas
long_duration_shared_users
variable
-- long_duration_shared_users Find the users whose average charging duration last longer than 10 hours when using shared charging stations. --
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 (duration_hours) DESC;