Exercise: Visualize the evolution of the temperature anomaly monthly average over time with a timeseries chart
Tips:
import pandas as pd
pd.read_csv()
pd.to_datetime()
In [ ]:
import pandas as pd
from bokeh.charts import TimeSeries, output_notebook, show
In [ ]:
# Get data
df = pd.read_csv('data/Land_Ocean_Monthly_Anomaly_Average.csv')
In [ ]:
# Process data
df['datetime'] = pd.to_datetime(df['datetime'])
df = df[['anomaly','datetime']]
In [ ]:
# Output option
output_notebook()
In [ ]:
# Create timeseries chart
t = TimeSeries(df, x='datetime')
In [ ]:
# Show chart
show(t)
Exercise: Style your plot
Ideas:
Charts arguments can be found: http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html#generic-arguments
In [ ]:
# Style your timeseries chart
t = TimeSeries(df, x='datetime', xlabel='time', ylabel='Anomaly(ºC)',
xgrid = False, ygrid=True, tools=False, width=950, height=300,
title="Temperature Anomaly(ºC) Monthly Average", palette=["grey"])
In [ ]:
# Show new chart
show(t)
Exercise: Add the moving annual average to your chart
Tips:
pd.rolling_mean()
In [ ]:
# Compute moving average
df['moving_average'] = pd.rolling_mean(df['anomaly'], 12)
In [ ]:
# Create chart with moving average
t = TimeSeries(df, x='datetime', xlabel='time', ylabel='Anomaly(ºC)',
xgrid = False, ygrid=True, tools=False, width=950, height=300, legend="bottom_right",
title="Temperature Anomaly(ºC) Monthly Average", palette=["grey", "red"])
In [ ]:
# Show chart with moving average
show(t)
In [ ]: