FantasticTony commited on
Commit
3121baf
·
1 Parent(s): cb8a883

:recycle: Add national trends and contextual insights to EV analysis

Browse files

Incorporated two new datasets to provide broader national context: vehicle offerings and registration trends by fuel type. Enhanced visualizations and storytelling, highlighting national light-duty vehicle patterns and their impact on EV adoption. Expanded user insights with clear comparative trends and key takeaways.

Files changed (1) hide show
  1. app.py +134 -57
app.py CHANGED
@@ -11,30 +11,87 @@ st.markdown("### Authors: Tony An, Nabeel Bashir, Devansh Kumar, Jiajun Li")
11
  data_path = 'data/Electric_Vehicle_Population_Data.csv'
12
  ev_data = pd.read_csv(data_path)
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Data Preparation
15
  ev_data[['Longitude', 'Latitude']] = ev_data['Vehicle Location'].str.extract(r'POINT \((-?\d+\.\d+) (-?\d+\.\d+)\)')
16
  ev_data['Latitude'] = pd.to_numeric(ev_data['Latitude'], errors='coerce')
17
  ev_data['Longitude'] = pd.to_numeric(ev_data['Longitude'], errors='coerce')
18
 
19
- # Write-up
20
  st.markdown("""
21
- Electric vehicles (EVs) represent a transformative shift in the transportation sector, combining technological innovation with environmental responsibility.
22
-
23
- Through this interactive article, we aim to uncover key trends in EV adoption, including the growing number of electric vehicles across counties in Washington State, the release patterns of EV models over the years, and the geographic distribution of EVs. By examining these trends, we can provide insights into the factors driving EV adoption and their implications for infrastructure and policy.
24
 
25
- ### Why Focus on Washington State?
26
- Washington State has emerged as a leader in promoting clean energy initiatives and adopting electric vehicles. With a robust network of charging stations and incentives for EV buyers, the state provides a rich dataset to analyze the adoption trends of electric vehicles. By focusing on a single state, we can gain deeper insights into localized patterns and challenges, which can be used to inform similar efforts in other regions.
27
-
28
- ### What You'll Discover
29
- - The distribution and characteristics of EVs across counties in Washington State.
30
- - The timeline of EV model releases.
31
- - Insights into infrastructure, including potential charging station locations.
32
 
33
- This analysis focuses on Washington State to provide a localized perspective and highlight trends at a manageable scale.
 
 
 
34
  """)
35
 
36
  # Central Interactive Visualization
37
- st.subheader("Explore EV Distribution by County")
38
  county_counts = ev_data['County'].value_counts().reset_index()
39
  county_counts.columns = ['County', 'Count']
40
 
@@ -50,40 +107,8 @@ county_counts['Color'] = county_counts['County'].apply(
50
  lambda x: 'blue' if x == selected_county else 'green'
51
  )
52
 
53
- # Contextual Visualization 0: EV Bar Counts by County
54
- fig_county = px.bar(
55
- county_counts,
56
- x='County',
57
- y='Count',
58
- title=f"Electric Vehicle Counts by {selected_county if selected_county != 'All' else 'County'}",
59
- labels={"Count": "Number of EVs", "County": "County"},
60
- color='County',
61
- color_discrete_map={
62
- selected_county: 'blue',
63
- 'Other': 'green'
64
- },
65
- height=500
66
- )
67
- st.plotly_chart(fig_county, use_container_width=True)
68
-
69
- # Contextual Visualization 1: Vehicle Model Trends
70
- ev_data['Model Year'] = pd.to_numeric(ev_data['Model Year'], errors='coerce')
71
- model_year_counts = ev_data_filtered['Model Year'].value_counts().reset_index()
72
- model_year_counts.columns = ['Year', 'Count']
73
- model_year_counts = model_year_counts.sort_values('Year')
74
-
75
- fig_year = px.line(
76
- model_year_counts,
77
- x='Year',
78
- y='Count',
79
- title="Trend of EV Models Released Over Time",
80
- labels={"Year": "Model Year", "Count": "Number of Models"},
81
- markers=True
82
- )
83
- st.plotly_chart(fig_year, use_container_width=True)
84
-
85
- # Contextual Visualization 2: Map of EV Locations
86
- st.subheader("Geographic Distribution of EVs")
87
  filtered_data = ev_data_filtered.dropna(subset=['Latitude', 'Longitude'])
88
  st.pydeck_chart(pdk.Deck(
89
  initial_view_state=pdk.ViewState(
@@ -107,25 +132,77 @@ st.pydeck_chart(pdk.Deck(
107
  }
108
  ))
109
 
 
 
 
 
 
 
 
 
110
  st.markdown("""
111
- ### Analysis and Key Takeaways
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
- 1. **County-Level Distribution**: King County stands out as the hub for electric vehicles in Washington State, accounting for the vast majority of EVs. This concentration aligns with the county's urban population density and robust infrastructure supporting EVs.
 
 
 
 
 
 
 
 
 
 
114
 
115
- 2. **Model Release Trends**: The timeline of EV model releases shows a significant surge in recent years, reflecting advancements in EV technology and increasing consumer demand. The spike in 2020-2021 likely corresponds to policy incentives and a growing focus on reducing carbon emissions.
 
 
 
 
116
 
117
- 3. **Geographic Insights**: The geographic visualization highlights key clusters of EV adoption, primarily around metropolitan areas. These clusters underline the importance of accessible charging stations and supportive local policies in driving EV adoption.
 
 
 
 
 
 
 
 
 
118
 
119
- ### Moving Forward
120
- As EV adoption continues to grow, insights from localized data like this can inform infrastructure planning and policy-making. Expanding charging networks, incentivizing adoption in underserved areas, and addressing technological barriers are crucial steps for achieving widespread EV integration.
 
 
 
 
 
121
 
 
122
  """)
123
 
124
- # Citations and Dataset Links
125
  st.markdown("""
126
  ### Sources
127
  1. Dataset: [Electric Vehicle Population Data](https://catalog.data.gov/dataset/electric-vehicle-population-data)
128
- 2. Additional Visualization Inspiration: [US Department of Energy EV Statistics](https://afdc.energy.gov/data)
129
-
130
- All visualizations and data preparation were created by the authors, datasets found online.
131
  """)
 
11
  data_path = 'data/Electric_Vehicle_Population_Data.csv'
12
  ev_data = pd.read_csv(data_path)
13
 
14
+ # Contextual Data 1 (National Trends: Vehicle Offerings)
15
+ contextual_data_1 = {
16
+ "Fuel Type": [
17
+ "Ethanol (E85)", "CNG (Dedicated and Bi-Fuel)", "Diesel", "Electricity*",
18
+ "Hybrid Electric", "Propane (Dedicated and Bi-Fuel)", "Hydrogen", "Methanol (M85)"
19
+ ],
20
+ "1991": [0, 0, 17, 0, 0, 0, 0, 2],
21
+ "1992": [1, 2, 14, 0, 0, 0, 0, 2],
22
+ "1993": [1, 2, 5, 0, 0, 0, 0, 4],
23
+ "1994": [1, 2, 12, 0, 0, 0, 0, 2],
24
+ "1995": [0, 10, 13, 1, 0, 0, 0, 2],
25
+ "1996": [1, 10, 12, 0, 0, 0, 0, 1],
26
+ "1997": [1, 9, 11, 3, 0, 3, 0, 1],
27
+ "1998": [2, 12, 11, 8, 0, 3, 0, 0],
28
+ "1999": [6, 16, 7, 16, 0, 5, 0, 0],
29
+ "2000": [8, 15, 3, 12, 2, 2, 0, 0],
30
+ "2001": [11, 16, 3, 10, 2, 5, 0, 0],
31
+ "2002": [16, 18, 4, 6, 3, 5, 0, 0],
32
+ "2003": [22, 16, 4, 5, 3, 1, 0, 0],
33
+ "2004": [19, 16, 7, 1, 3, 1, 0, 0],
34
+ "2005": [24, 5, 8, 0, 8, 0, 0, 0],
35
+ "2006": [22, 5, 6, 0, 8, 0, 0, 0],
36
+ "2007": [31, 1, 7, 0, 11, 0, 0, 0],
37
+ "2008": [31, 1, 6, 1, 16, 1, 0, 0],
38
+ "2009": [36, 1, 12, 1, 19, 1, 0, 0],
39
+ "2010": [34, 1, 14, 1, 20, 0, 0, 0],
40
+ "2011": [72, 1, 16, 2, 29, 0, 0, 0],
41
+ "2012": [62, 6, 17, 6, 31, 1, 1, 0],
42
+ "2013": [84, 11, 22, 15, 38, 6, 1, 0],
43
+ "2014": [90, 19, 35, 16, 43, 14, 2, 0],
44
+ "2015": [84, 17, 39, 27, 46, 10, 3, 0],
45
+ "2016": [66, 12, 29, 29, 31, 5, 3, 0],
46
+ "2017": [45, 9, 21, 51, 44, 8, 2, 0],
47
+ "2018": [53, 9, 38, 57, 43, 7, 2, 0],
48
+ "2019": [40, 7, 30, 72, 64, 7, 4, 0],
49
+ "2020": [25, 10, 20, 83, 81, 8, 4, 0],
50
+ "2021": [14, 4, 30, 95, 127, 4, 5, 0],
51
+ "2022": [17, 0, 29, 132, 149, 0, 5, 0],
52
+ "2023": [10, 0, 22, 116, 127, 0, 5, 0],
53
+ "2024": [5, 0, 20, 149, 143, 0, 5, 0],
54
+ }
55
+ contextual_df_1 = pd.DataFrame(contextual_data_1)
56
+
57
+ # Contextual Data 2 (National Trends: Vehicle Registration Changes)
58
+ contextual_data_2 = {
59
+ "Fuel Type": ["Gasoline", "Flex Fuel", "Diesel", "Hybrid Electric", "Electric",
60
+ "Biodiesel", "PHEV", "Compressed Natural Gas", "Hydrogen",
61
+ "Propane", "Bi-Fuel", "Other", "Unspecified"],
62
+ "2016-2017": [1.1, 10.0, 4.7, 7.3, 25.9, None, 26.3, -8.8, 59.6, 5.3, None, -0.3, -6.9],
63
+ "2017-2018": [0.7, 6.4, 2.0, 4.9, 33.7, None, 25.3, -8.9, 34.1, -58.3, None, -3.9, -4.5],
64
+ "2018-2019": [1.0, 4.5, 3.2, 6.0, 26.9, None, 14.0, -8.7, 62.0, -20.0, None, -4.7, -2.4],
65
+ "2019-2020": [0.3, 1.6, 3.5, 6.3, 23.1, None, 9.7, -7.5, 9.4, 9.1, None, -5.8, -4.7],
66
+ "2020-2021": [3.6, -32.1, -24.6, 12.8, 29.9, None, 21.5, -1037.8, -18.2, 99.9, None, None, None],
67
+ "2021-2022": [0.3, -1.4, 0.6, 12.2, 40.3, 13.1, 25.3, -135.0, 20.5, -7.2, None, None, None],
68
+ "2022-2023": [-1.5, -10.0, -1.7, 8.7, 21.5, 1.4, 11.5, -16.1, 8.4, -8.9, -43.3, -10.5, None]
69
+ }
70
+ contextual_df_2 = pd.DataFrame(contextual_data_2)
71
+
72
+
73
  # Data Preparation
74
  ev_data[['Longitude', 'Latitude']] = ev_data['Vehicle Location'].str.extract(r'POINT \((-?\d+\.\d+) (-?\d+\.\d+)\)')
75
  ev_data['Latitude'] = pd.to_numeric(ev_data['Latitude'], errors='coerce')
76
  ev_data['Longitude'] = pd.to_numeric(ev_data['Longitude'], errors='coerce')
77
 
78
+ # Introduction Story
79
  st.markdown("""
80
+ Electric vehicles (EVs) are no longer a niche technology; they represent the future of transportation. From bustling urban hubs to quiet suburban roads, the adoption of EVs is reshaping mobility and environmental policy. This interactive story highlights **Washington State's EV trends**, places them within a **national context**, and explores the remarkable transformation of vehicle technology and registration trends.
 
 
81
 
82
+ Through maps, charts, and insights, we uncover:
83
+ - The **geographic distribution** of EVs in Washington State.
84
+ - The rapid growth of EV models over time.
85
+ - National trends in vehicle offerings and registration changes.
86
+ """)
 
 
87
 
88
+ # Visualization 1: Geographic Distribution
89
+ st.subheader("Where Are Electric Vehicles Adopted the Most?")
90
+ st.markdown("""
91
+ Washington State's **King County** is at the forefront of EV adoption, with over 107,000 registered EVs. Snohomish and Pierce Counties follow, showing that urban infrastructure and policies are key drivers of EV growth.
92
  """)
93
 
94
  # Central Interactive Visualization
 
95
  county_counts = ev_data['County'].value_counts().reset_index()
96
  county_counts.columns = ['County', 'Count']
97
 
 
107
  lambda x: 'blue' if x == selected_county else 'green'
108
  )
109
 
110
+ # Visualization 1: Map of EV Locations
111
+ # st.subheader("Geographic Distribution of EVs")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  filtered_data = ev_data_filtered.dropna(subset=['Latitude', 'Longitude'])
113
  st.pydeck_chart(pdk.Deck(
114
  initial_view_state=pdk.ViewState(
 
132
  }
133
  ))
134
 
135
+ # Visualization 2: Vehicle Model Trends
136
+ ev_data['Model Year'] = pd.to_numeric(ev_data['Model Year'], errors='coerce')
137
+ model_year_counts = ev_data_filtered['Model Year'].value_counts().reset_index()
138
+ model_year_counts.columns = ['Year', 'Count']
139
+ model_year_counts = model_year_counts.sort_values('Year')
140
+
141
+ # Visualization 2: Trend of EV Models
142
+ st.subheader("How Have EV Models Evolved Over Time?")
143
  st.markdown("""
144
+ The post-2010 era witnessed an explosion in EV models. This surge aligns with major technological advancements, government incentives, and growing consumer awareness.
145
+ """)
146
+ fig_year = px.line(
147
+ model_year_counts,
148
+ x='Year',
149
+ y='Count',
150
+ title="Trend of EV Models Released Over Time",
151
+ labels={"Year": "Model Year", "Count": "Number of Models"},
152
+ markers=True
153
+ )
154
+ st.plotly_chart(fig_year, use_container_width=True)
155
+
156
+ # Visualization 3: National Trends in Vehicle Offerings
157
+ st.subheader("National Light-Duty Vehicle Trends")
158
+ st.markdown("""
159
+ The national landscape highlights a **shift to clean energy**. Electric and hybrid vehicles have seen exponential growth, while older fuels like **diesel** and **CNG** stagnate or decline.
160
+ """)
161
 
162
+ contextual_melted_1 = pd.melt(contextual_df_1, id_vars=['Fuel Type'], var_name='Year', value_name='Models Offered')
163
+ fig_contextual_1 = px.bar(
164
+ contextual_melted_1,
165
+ x='Year',
166
+ y='Models Offered',
167
+ color='Fuel Type',
168
+ title='National Light-Duty Vehicle Offerings by Fuel Type',
169
+ labels={"Year": "Year", "Models Offered": "Number of Models Offered"},
170
+ barmode='stack'
171
+ )
172
+ st.plotly_chart(fig_contextual_1, use_container_width=True)
173
 
174
+ # Visualization 4: Registration Trends
175
+ st.subheader("Are EV Registrations Outpacing Traditional Vehicles?")
176
+ st.markdown("""
177
+ Recent years show **double-digit growth** in electric vehicle registrations, outpacing traditional fuels. Hybrid and electric vehicles dominate registration increases, reflecting shifting consumer preferences.
178
+ """)
179
 
180
+ contextual_melted_2 = pd.melt(contextual_df_2, id_vars=['Fuel Type'], var_name='Year', value_name='Change (%)')
181
+ fig_contextual_2 = px.line(
182
+ contextual_melted_2,
183
+ x='Year',
184
+ y='Change (%)',
185
+ color='Fuel Type',
186
+ title='Change in U.S. Light-Duty Vehicle Registration Counts',
187
+ labels={"Year": "Year", "Change (%)": "Percentage Change"}
188
+ )
189
+ st.plotly_chart(fig_contextual_2, use_container_width=True)
190
 
191
+ # Comparative Insights
192
+ st.subheader("Key Insights")
193
+ st.markdown("""
194
+ - **King County** dominates EV adoption in Washington State.
195
+ - **Post-2010 growth** in EV models highlights technological and policy-driven momentum.
196
+ - Nationally, **electric vehicles lead registration growth**, while gasoline and diesel struggle to maintain their foothold.
197
+ - Hybrid vehicles serve as a bridge, reflecting steady growth alongside BEVs.
198
 
199
+ Electric vehicles are no longer a future promise—they are here, driving a revolution in transportation and sustainability.
200
  """)
201
 
202
+ # Citations
203
  st.markdown("""
204
  ### Sources
205
  1. Dataset: [Electric Vehicle Population Data](https://catalog.data.gov/dataset/electric-vehicle-population-data)
206
+ 2. Contextual Data: [U.S. Light-Duty Vehicle Offerings](https://afdc.energy.gov/data/10303)
207
+ 3. Contextual Data: [U.S. Vehicle Registration Trends](https://afdc.energy.gov/data/10881)
 
208
  """)