Skip to content

Instantly share code, notes, and snippets.

@wandabwa2004
Created July 22, 2019 10:23
Show Gist options
  • Save wandabwa2004/7ffcb9d5a954dc24a416886badac3b36 to your computer and use it in GitHub Desktop.
Save wandabwa2004/7ffcb9d5a954dc24a416886badac3b36 to your computer and use it in GitHub Desktop.
ot = df.sample(frac=.1, random_state=1111)
ot.sort_index(inplace=True)
ot['mean'] = ot['compound'].expanding().mean()
ot['rolling'] = ot['compound'].rolling('12h').mean()
fig = plt.figure(figsize=(20,5))
ax = fig.add_subplot(111)
ax.scatter(ot['review date'],ot['compound'], label='Tweet Sentiment')
ax.plot(ot['review date'],ot['rolling'], color ='g', label='Rolling Mean')
ax.plot(ot['review date'],ot['mean'], color='r', label='Expanding Mean')
ax.set(title='Te Papa Trip Advisor Reviews over Time', xlabel='Date', ylabel='Sentiment')
ax.legend(loc='best')
fig.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment