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 [1]:
import pandas as pd
from bokeh.charts import TimeSeries, output_notebook, show
In [2]:
# Get data
df = pd.read_csv('data/Land_Ocean_Monthly_Anomaly_Average.csv')
In [3]:
# Process data
df['datetime'] = pd.to_datetime(df['datetime'])
df = df[['anomaly','datetime']]
In [4]:
# Output option
output_notebook()
In [5]:
# Create timeseries chart
t = TimeSeries(df, x='datetime')
In [6]:
# Show chart
show(t)
Out[6]:
Exercise: Style your plot
Ideas:
Charts arguments can be found: http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html#generic-arguments
In [9]:
# Style your timeseries chart
t = TimeSeries(df, x='datetime', xlabel='time', ylabel='Anomaly(ºC)',
xgrid = False, ygrid=True, tools=True, width=950, height=300,
title="Temperature Anomaly(ºC) Monthly Average", palette=["grey"])
In [10]:
# Show new chart
show(t)
Out[10]:
Exercise: Add the moving annual average to your chart
Tips:
pd.rolling_mean()
In [11]:
# Compute moving average
df['moving_average'] = pd.rolling_mean(df['anomaly'], 12)
In [13]:
# Create chart with moving average
t = TimeSeries(df, x='datetime', xlabel='time', ylabel='Anomaly(ºC)',
xgrid = False, ygrid=True, tools=True, width=950, height=300, legend="bottom_right",
title="Temperature Anomaly(ºC) Monthly Average", palette=["grey", "red"])
In [14]:
# Show chart with moving average
show(t)
Out[14]:
In [ ]: