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 required libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Load the datasets
private = pd.read_csv("private_ev_charging.csv")
public = pd.read_csv("public_ev_charging.csv")
sales = pd.read_csv("ev_sales.csv")

# outer join private with public charging dataset
charging_combined = private.merge(public, on='year', how='outer', indicator=True)
# only combine those with both
charging_temp = charging_combined[charging_combined['_merge'] == 'both']
# drop the column
charging_temp = charging_temp.drop(columns=['_merge'])

# inspect sum of sales grouped by year
total_sales = sales.groupby('year')['sales'].sum().reset_index()
print(total_sales)
ev_sales_2018 = 361315

# complete dataset by combining sales with left join and drop null values
complete_df = charging_temp.merge(total_sales, how='left', on='year')
complete_df = complete_df.dropna(subset='sales')
print(complete_df)

# plot data to visualize trends
fig, ax = plt.subplots()
sns.lineplot(data=complete_df, x='year', y='private_ports', label='Private Ports')
sns.lineplot(data=complete_df, x='year', y='public_ports', label='Public Ports')
sns.lineplot(data=complete_df, x='year', y='sales', label='Total Sales')

# set the title and labels and legend
ax.set_title('EV Ports and Sales')
ax.set(xlabel='Year', ylabel='Count')
ax.legend(loc='upper left')
plt.show()

trend='same'