Wildfires 🔥 & federal fire-fighting costs 💵(fire suppressions only) in the U.S.
Data Source: Kaggle
# Import libraries like you do when running python locally
import pandas as pd
import asyncio
import panel as pn
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from panel.io.pyodide import show
# Read in the data as pandas dataframe
data = pd.read_csv("./Federal_Firefighting_Costs_Suppression_Only.csv")
data['Year'] = pd.to_datetime(data['Year'] , format ='%Y')
# Clean up data by removing special characters in all columns
for feat in list(data.drop('Year', axis=1)):
data[feat] = data[feat].str.replace(',', '', regex=False)
data[feat] = data[feat].str.replace('$', '', regex=False)
data[feat] = pd.to_numeric(data[feat])
# Calculate Acers burnt per fire over time
data['Area (in acres) burnt per fire'] = data['Acres']/data['Fires']
# Visualize
cds = ColumnDataSource(data=ColumnDataSource.from_df(data))
p1 = figure(height=400, width=600,x_axis_type="datetime", title = "Expenditure (USD)", title_location="above")
p2 = figure(height=400, width=600,x_axis_type="datetime", title = "Wildfire from 1983 to 2020", title_location="above")
p3 = figure(height=400, width=600,x_axis_type="datetime", title = "Area burnt (acers)", title_location="above")
p4 = figure(height=400, width=600,x_axis_type="datetime", title = "Area burnt per fire (acres)", title_location="above")
p1.line('Year', 'Total', source=cds, line_color='#7BC55F',legend_label="Total", line_width =3)
p1.line('Year', 'DOIAgencies', source=cds, line_color='#6697EB',legend_label="DOI Agencies", line_width =3)
p1.line('Year', 'ForestService', source=cds, line_color='#E5754C',legend_label="Forest Service", line_width =3)
p2.line('Year', 'Fires',source=cds, line_color="#ef476f", line_width =3)
p3.line('Year', 'Acres' ,source=cds, line_color="#72ddf7", line_width =3)
p4.line('Year', 'Area (in acres) burnt per fire',source=cds, line_color="#9b5de5", line_width =3)
# Customize plots
p1.add_layout(p1.legend[0], 'right')
p1.title.text_font_size = '18pt'
p2.title.text_font_size = '18pt'
p3.title.text_font_size = '18pt'
p4.title.text_font_size = '18pt'
p1.left[0].formatter.use_scientific = False
p2.left[0].formatter.use_scientific = False
p3.left[0].formatter.use_scientific = False
p4.left[0].formatter.use_scientific = False
# Display
await show(p2, "plot1")
await show(p3, "plot2")
await show(p4, "plot3")
await show(p1, "plot4")