Created
October 29, 2019 16:23
-
-
Save fclesio/ce14a5fdc22dc11a6ab9aaff902ce91c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Some graphs with rolling average | |
date_range = [2003, 2004, 2005, 2006, 2007, | |
2008, 2009, 2010, 2011, 2012, | |
2013, 2014, 2015, 2016, 2017, | |
2018] | |
def get_graph_ts_rolling_average(ts, title, window, date_range=date_range): | |
"""Generate graph of a Time Series with a simple rolling average | |
Parameters | |
---------- | |
ts : Pandas Dataframe column | |
Dataframe column with a metric to be ploted | |
title : Pandas Dataframe | |
Graph title to be displayed | |
window : int | |
Rolling back window to be considered in the average | |
date_range : Array | |
Array to be used in the ploting. Matplotlib has a | |
very bad way to deal with that, so I need to use this | |
workaround to place all years properly | |
Returns | |
------- | |
""" | |
plt.figure(figsize=(20,10)) | |
plt.plot(date_range, ts.rolling(window=window, center=False).mean(), label='gini'); | |
plt.title(f'{title}{window}') | |
plt.xlabel('Years') | |
plt.ylabel('Gini Index') | |
plt.xticks(gini_df.index) | |
plt.legend() | |
get_graph_ts_rolling_average(gini_df['gini'], | |
'Rolling Average in Gini Index in Brasileirão - Rolling Average window=', | |
3, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment