Skip to content

The US Government's Alternative Fuels Data Center collects records of electric vehicle (EV) charging infrastructure, including charging ports and station locations, as well as sales of electric vehicles. With the EV market rapidly evolving, understanding trends in charging facilities and sales is essential to inform strategic planning.

As a data scientist working for a leading EV charging network operator, you recognize the potential in this data and start wrangling and visualizing the aggregated yearly data.

This yearly data captured in December of each year encompasses a record of EV charging port installations and station localities spanning roughly ten years, capturing both public and private charging environments.


The Data

 

private_ev_charging.csv

VariableDescription
yearYear of data collection
private_portsThe number of available charging ports owned by private companies in a given year
private_station_locationsThe number of privately owned station locations for EV charging

public_ev_charging.csv

VariableDescription
yearYear of data collection
public_portsThe number of available charging ports under public ownership in a given year
public_station_locationsThe number of publicly owned station locations for EV charging

The sales information is available for each model and year in the ev_sales.csv file:

VariableDescription
VehicleElectric vehicle model
yearYear of data collection
salesThe number of vehicles sold in the US
# Import required libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
# Start coding here
private_ev_charging = pd.read_csv('private_ev_charging.csv')
public_ev_charging = pd.read_csv('public_ev_charging.csv')
ev_sales = pd.read_csv('ev_sales.csv')
# How many vehicles were sold in 2018 in total? Save the answer as a numeric variable called ev_sales_2018.
year_2018_sales = ev_sales[ev_sales['year'] == 2018]
#year_2018_sales['total_sales'] = sum(year_2018_sales['sales'])
total_sales_2018 = year_2018_sales.groupby('year')['sales'].sum().reset_index()
ev_sales_2018 = total_sales_2018.iloc[0,1]
ev_sales_2018
total_sales = ev_sales.groupby('year')['sales'].sum().reset_index()

puplic_and_private = public_ev_charging.merge(private_ev_charging, on='year', how='inner')
all_data = puplic_and_private.merge(total_sales, on='year', how='inner')

fig, ax = plt.subplots()

plt.plot(all_data['year'], all_data['public_ports'], label='Public Ports')
plt.plot(all_data['year'], all_data['private_ports'], label='Private Ports')
plt.plot(all_data['year'], all_data['sales'], label='Total Sales')
plt.xlabel('Year')
plt.ylabel('Count')
plt.show()
trend = 'same'
trend