Sententia provides access to media sentiment data from the Bureau for Economic research.
This homepage for the {sententia} python
package is at
https://github.com/71point4/pysententia.
You can find the homepage for the {sententia} R
package is at
https://github.com/71point4/sententia.
Install from GitHub.
install git+https://github.com/71point4/pysententia
To build the documentation:
make -C docs/ html
To access the API you’ll need to first specify an API key as provided to you by the BER.
import os
key = os.getenv('SENTENTIA_KEY')
Besides providing sentiment calculations from different word-list dictionaries, the API interface provides access to the various permutations that is available in calculating a sentiment score (Within text and across time):
- Sentiment calculation
WITHIN
the article- In the API this is set by the
aggr
parameter
- In the API this is set by the
- Sentiment calculation
ACCROSS
a time period- This does not need to be set. API returns four aggregations:
mean_sentiment
relative
absolute
sent_log
- This does not need to be set. API returns four aggregations:
from pysententia import Sententia
sent = Sententia(key = key)
Get media sentiment index values for specified media source, model, topic, dictionary, frequency, and aggregation method combination.
sent.sent_index(
source = "businessday",
topic = "global",
freq = "month",
dict = "loughran",
aggr = "sent_logit"
)
Get a count of the number of articles for a specified media source, model, topic, and frequency of aggregation.
sent.sent_counts(
source = "all",
topic = "global",
freq = "week"
)
Get a count of the number of positive and negative articles for a specified model, topic, dictionary, aggregation method, and frequency.
sent.sent_date_polarity(
source = "all",
topic = "global",
freq = "week",
dict = "loughran",
aggr = "sent_logit"
)
Get the top 50 most frequently occurring positive and negative words for a specified model, topic, dictionary, aggregation method, and frequency. The timeframe over which these words are selected depends on the specified frequency (day = 30 days, week = 3 months, month = 6 months).
sent.sent_word_polarity(
source = "all",
topic = "economy",
freq = "day",
dict = "loughran"
)