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
Variable | Description |
---|---|
year | Year of data collection |
private_ports | The number of available charging ports owned by private companies in a given year |
private_station_locations | The number of privately owned station locations for EV charging |
public_ev_charging.csv
Variable | Description |
---|---|
year | Year of data collection |
public_ports | The number of available charging ports under public ownership in a given year |
public_station_locations | The 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:
Variable | Description |
---|---|
Vehicle | Electric vehicle model |
year | Year of data collection |
sales | The number of vehicles sold in the US |
# Import required libraries
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Start coding here
private_ev = pd.read_csv('private_ev_charging.csv')
public_ev = pd.read_csv('public_ev_charging.csv')
ev_sales = pd.read_csv('ev_sales.csv')
private_ev.head()
public_ev.head()
ev_sales.head()
ev_sales_sum = ev_sales.groupby("year").sum().reset_index()
print(ev_sales_sum)
ev_sales_2018 = int(ev_sales_sum[ev_sales_sum["year"]==2018]["sales"])
print(ev_sales_2018)
private_public = private_ev.merge(public_ev, on ='year', how= 'outer')
private_public.isna()
private_public.dropna()
private_public.drop(["private_station_locations","public_station_locations"], axis=1)
private_public.groupby("year")
complete = private_public.merge(ev_sales, on='year', how="left")
complete = complete.dropna()