Created
October 20, 2016 16:29
-
-
Save rouli/8dd7000fe3111b88ce317a4fd3023a18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def readfile(filename): | |
with open(filename) as f: | |
df = pd.read_html(f)[0] | |
df.columns = ['date', 'views'] | |
df['date'] = df['date'].apply(lambda x:dateutil.parser.parse(x)) | |
df = df.set_index('date') | |
df['day_of_week'] = df.index.map(lambda t:t.dayofweek) | |
df['max_weekly_value'] = df.views-pd.rolling_max(df.views, 7)==0 | |
return df | |
weekdays = ['Mondays', 'Tuesdays', 'Wednesdays', 'Thursdays', 'Fridays', 'Saturdays', 'Sundays'] | |
df.views.plot(figsize=(16,9), lw=2) | |
plt.axvline(pd.to_datetime('2011-11-01'), color='r', linestyle='--', lw=2, alpha=0.5, label='November 1st') | |
plt.axvline(pd.to_datetime('2012-11-01'), color='r', linestyle='--', lw=2, alpha=0.5) | |
plt.axvline(pd.to_datetime('2013-11-01'), color='r', linestyle='--', lw=2, alpha=0.5) | |
plt.axvline(pd.to_datetime('2014-11-01'), color='r', linestyle='--', lw=2, alpha=0.5) | |
plt.axvline(pd.to_datetime('2015-11-01'), color='r', linestyle='--', lw=2, alpha=0.5) | |
plt.axvline(pd.to_datetime('2016-01-14'), color='g', linestyle='--', lw=2, alpha=0.5, label='Featured on "It\'s Always Sunny in Philadelphia"') | |
plt.legend(loc=2) | |
plt.title('Number of Youtube Views\nWyclef Jean - Gone till November') | |
plt.ylim((0,7000)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment