https://github.com/bcongdon/pyvethirtyeight
:us: Python wrapper for Fivethirtyeight's Election Forecasts
https://github.com/bcongdon/pyvethirtyeight
fivethirtyeight forecast python-wrapper
Last synced: 4 months ago
JSON representation
:us: Python wrapper for Fivethirtyeight's Election Forecasts
- Host: GitHub
- URL: https://github.com/bcongdon/pyvethirtyeight
- Owner: bcongdon
- License: mit
- Created: 2016-10-09T19:47:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-22T23:23:32.000Z (over 8 years ago)
- Last Synced: 2025-01-17T07:41:38.826Z (5 months ago)
- Topics: fivethirtyeight, forecast, python-wrapper
- Language: Python
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PyveThirtyEight
> A Python wrapper for the 2016 [FiveThirtyEight](projects.fivethirtyeight.com/2016-election-forecast/) Presidential Election Forecast[](https://badge.fury.io/py/pyvethirtyeight)
[](https://travis-ci.org/bcongdon/pyvethirtyeight)## Installation
```
pip install pyvethirtyeight
```## Usage
```python
from pyvethirtyeight import President, Senate# Presidential Election Forecasts
f = President()# Latest Forecasts (Unordered)
latest = f.latest_forecasts()
latest[0].party # 'D'# Current Leader (returns Forecast of latest leader)
leader = f.current_leader()
print(leader.models['plus']['winprob']) # 83.99# Current Leader by Model
leader = f.current_leader(model='now')
print(leader.models['now']['winprob']) # 90.4# All Forecasts
all_forecasts = f.all_forecasts()# Same methods also work with Senate predictions
s = Senate()
print(s.latest_forecasts()[0].models['polls']['winprob']) # 67.33596
```#### The Forecast Object
A `Forecast` is the prediction of the FiveThirtyEight model for a particular candidate at a particular moment in timeA `Forecast` has keys:
- date (datetime) -> Forecast date
- party (str) -> Candidate's party initial
- candidate (str) -> Candidate's name
- models (Dict) -> Dict of model predictions associated with candidate