July 2017
Beginner to intermediate
312 pages
7h 27m
English
Firstly, we'll compute the average sentiment score per month:
df['sentiment'].resample('M').mean()
The argument of the resample() method indicates time window. We could also use other periods, for example:
There are many other possible ways to resample timeseries data. It can be found in the Pandas library documentation: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases.
Then, we use matplotlib to plot the average monthly sentiment as follows:
import matplotlib.pyplot as plt import matplotlib matplotlib.style.use('ggplot') df['sentiment'].resample('M').mean().plot(title = "Sentiment over Time", lw =2, ylim = (-1,1)) ...Read now
Unlock full access