Skip to content

Commit

Permalink
Add predator-prey data
Browse files Browse the repository at this point in the history
  • Loading branch information
wesselb committed Apr 28, 2022
1 parent 26b23ff commit 7e99bcf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def _import_and_execute(name, kw_args, monkeypatch):
("mauna_loa", {"detrend_method": "gp"}),
("mauna_loa", {"detrend_method": "linear"}),
("miso", {}),
("predprey", {}),
("toy_sines", {}),
("vix", {}),
],
Expand Down
36 changes: 36 additions & 0 deletions wbml/data/predprey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pandas as pd

from .data import data_path, resource

__all__ = ["load"]


def load():
"""Predator–prey data.
Source:
The data is a digitised version of the historical data by D. R. Hundley:
http://people.whitman.edu/~hundledr/courses/M250F03/LynxHare.txt
Returns:
:class:`pd.DataFrame`: Predator–prey data.
"""
_fetch()

df = pd.read_csv(
data_path("pred_prey", "LynxHare.txt"),
header=None,
delim_whitespace=True,
index_col=0,
)
df.index.name = "year"
df.columns = ["hare", "lynx"]

return df


def _fetch():
resource(
target=data_path("pred_prey", "LynxHare.txt"),
url="http://people.whitman.edu/~hundledr/courses/M250F03/LynxHare.txt",
)

0 comments on commit 7e99bcf

Please sign in to comment.