Skip to content

Instantly share code, notes, and snippets.

@wandabwa2004
Created July 22, 2019 10:02
Show Gist options
  • Save wandabwa2004/9a144b830773718ededa5f457f106b2d to your computer and use it in GitHub Desktop.
Save wandabwa2004/9a144b830773718ededa5f457f106b2d to your computer and use it in GitHub Desktop.
df.index = pd.DatetimeIndex(df["review date"])
df = df.sort_index()
df['mean'] = df['compound'].expanding().mean()
df['rolling'] = df['compound'].rolling('24h').mean()
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(20,5))
ax = fig.add_subplot(111)
ax.scatter(df['review date'],df['compound'], label='Tweet Sentiment')
ax.plot(df['review date'],df['rolling'], color ='g', label='Rolling Mean')
ax.plot(df['review date'],df['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