<jupyter_start><jupyter_text>**New York EV Chargins Station - Charging Session Analysis** When we are away from home, there are thousands of charging stations that you can take advantage of across New York State. This level of charging is known as Level 2 and it is at least two times faster than Level 1.Level 2 charging stations are mainly installed at stores, office buildings, municipal parking lots, parks, hotels, theaters and hospitals. All Level 2 charging stations have a common plug that all electric cars can use, while DC fast chargers may not be compatible with every model.DC fast charging uses direct current (DC), as opposed to households which use alternating current (AC), and can provide close to a full charge in under an hour. Only public sites can support DC fast charging and they are most often installed along major travel corridors to support long distance drivers.Currently, there are 6471 Level 2 Charging ports and 729 DC Fast Charging ports available in New York. Most of the Level 2 ports are owned by ChargePoint and Tesla owns most of the DC Fast Charging stations.<jupyter_code>#Importing libraries needed for EDA

import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

# Suppress all warnings
import warnings
warnings.filterwarnings('ignore')

import seaborn as sns<jupyter_output><empty_output><jupyter_text>**NY EV Charging Sessions Dataset****Description:** New York State EV Charging Session details such as charging levels, duration, connectors.  **Size:** 30 MB  **Source:** nyserda.ny.gov  **Format:** Excel (xlsx) **Access Method:** Downloaded from [nyserda.ny.gov](https://www.nyserda.ny.gov/-/media/Files/Publications/Research/Transportation/EValuateNY-ZIP-File.zip?la=en)  **NY EV Charging Sessions - Energy Usage**<jupyter_code>#Reading the Excel spreadsheet and loading into pandas dataframe.
charge_sesssion = pd.read_excel('assets/EValuateNY-ZIP-File/resources.xlsx', 'Charging Use',usecols='A:I')
charge_sesssion.head()
charge_sesssion.info()
#Creating the Quarter column from the Charge Session start date
charge_sesssion['quarter'] = pd.PeriodIndex(charge_sesssion["Start Date"], freq='Q')
charge_sesssion.head()
#Making a copy of dataframe
charge_sesssion_duration = charge_sesssion
charge_sesssion_duration.columns
#Calculating the Average Energy grouping by quarter
charge_sesssion['Avg_Energy'] = charge_sesssion.groupby(['quarter'])['Energy (kWh)'].transform('mean')
#Calculating the Median Energy grouping by quarter
charge_sesssion['Median_Energy'] = charge_sesssion.groupby(['quarter'])['Energy (kWh)'].transform('median')
#Renaming column name
charge_sesssion = charge_sesssion.rename(columns={'Energy (kWh)' : 'Energy_kWh'})
##Calculating the Total Energy grouping by quarter
charge_sesssion['Total_Energy'] = charge_sesssion.groupby(['quarter'])['Energy_kWh'].transform('sum')
charge_sesssion.head()
charge_sesssion.info()
#Converting the datatype of quarter to string for plotting
charge_sesssion['quarter'] = charge_sesssion['quarter'].astype('str')
charge_sesssion.head()
#Keeping only the columns needed for plotting
charge_session_final = charge_sesssion[['quarter','Total_Energy','Avg_Energy','Median_Energy']]
#Dropping the duplicates
charge_session_final = charge_session_final.drop_duplicates()
charge_session_final.head()
#For sorting the data by quarted, creating a new column with just numbers
charge_session_final['q'] = charge_session_final['quarter'].str.replace(r'\D', '')
#Sorting the dataset 
charge_session_final= charge_session_final.sort_values("q")
#Plotting the EV Charging session - Engery use over time

fig, ax1 = plt.subplots(figsize=(20,6))
color = 'tab:green'
ax1.set_title('NY EV Charging Stations - Energy Use Over Time', fontsize=16)
ax1.set_xlabel('Quarter', fontsize=16)
ax2 = sns.barplot(x='quarter', y='Avg_Energy', data = charge_session_final, palette='summer')
                  #order=charge_session_final.sort_values('Avg_Energy',ascending = True).quarter)
ax1.tick_params(axis='y')
ax1.set_ylabel('Avg Energy Used', fontsize=16, color=color)
ax2 = ax1.twinx()
color = 'tab:red'
ax1.set_xlabel('Quarter', fontsize=16)
ax2 = sns.lineplot(x='quarter', y='Total_Energy', data = charge_session_final, sort=True, color=color)
ax2.tick_params(axis='y', color=color)

ax2.set_ylabel('Total Energy', fontsize=16, color=color)
#plt.xticks(rotation=45)

for tick in ax1.get_xticklabels():
    tick.set_rotation(45)
    
plt.show()
fig.savefig('ny_charge_energy.png')<jupyter_output><empty_output><jupyter_text>We tried to create a twin plot (bar chart + Line chart) to show the engergy use over time and total energy used by quarter.  **NY EV Charging Sessions Duration**<jupyter_code>#Creating dataset for EV Charging session duration
charge_sesssion_duration = charge_sesssion_duration[['quarter','Network','Charging Time (hours)','Total Duration (hours)','Charging Sessions']]
# Renaming the columns
charge_sesssion_duration = charge_sesssion_duration.rename(columns={'Charging Time (hours)' : 'Charging_time', 'Total Duration (hours)':'Total_Duration', 'Charging Sessions': 'Charging_Sessions'})
charge_sesssion_duration.head()
#Calculating Total charging time , grouping by quarter
charge_sesssion_duration['Total_Charging_Time'] = charge_sesssion_duration.groupby(['quarter'])['Charging_time'].transform('sum')
#Calculating Total charging sessions , grouping by quarter
charge_sesssion_duration['Total_Charging_Sessions'] = charge_sesssion_duration.groupby(['quarter'])['Charging_Sessions'].transform('sum')
#Dropping duplicate rows
charge_sesssion_duration = charge_sesssion_duration.drop_duplicates()
#Keeping only the columns needed for plotting
charge_sesssion_duration_final = charge_sesssion_duration[['quarter','Total_Charging_Time','Total_Charging_Sessions']]
charge_sesssion_duration_final = charge_sesssion_duration_final.drop_duplicates()
charge_sesssion_duration_final.info()
#Changing the datatype to string
charge_sesssion_duration_final['quarter'] = charge_sesssion_duration_final['quarter'].astype('str')
charge_sesssion_duration_final['q'] = charge_sesssion_duration_final['quarter'].str.replace(r'\D', '')
charge_sesssion_duration_final= charge_sesssion_duration_final.sort_values("q")
#Plotting the EV Charging session Duration

fig1, bx1 = plt.subplots(figsize=(20,6))
color = 'tab:orange'
bx1.set_title('NY EV Charging Stations - Session Duration', fontsize=16)
bx1.set_xlabel('Quarter', fontsize=16)
bx1 = sns.barplot(x='quarter', y='Total_Charging_Time', data = charge_sesssion_duration_final, palette='OrRd')
bx1.tick_params(axis='y')
bx1.set_ylabel('Charging Time in Hours', fontsize=16, color=color)
bx2 = bx1.twinx()
color = 'tab:green'
bx1.set_xlabel('Quarter', fontsize=16)
bx2 = sns.lineplot(x='quarter', y='Total_Charging_Sessions', data = charge_sesssion_duration_final, sort=True, color=color)
bx2.tick_params(axis='y', color=color)

bx2.set_ylabel('Charging Sessions', fontsize=16, color=color)
#plt.xticks(rotation=45)

for tick in bx1.get_xticklabels():
    tick.set_rotation(45)
    
plt.show()
fig1.savefig('ny_charge_duration.png')<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup