A python package for loading and preprocessing the FARS database
Project description
FARS Cleaner fars-cleaner
fars-cleaner
is a Python library for downloading and pre-processing data
from the Fatality Analysis Reporting System, collected annually by NHTSA since
1975 ().
Installation
The preferred installation method is through conda
.
conda install -c conda-forge fars-cleaner
You can also install with pip.
pip install foobar
Usage
Downloading FARS data
The FARSFetcher
class provides an interface to download and unzip selected years from the NHTSA FARS FTP server.
The class uses pooch
to download and unzip the selected files. By default, files are unzipped to your OS's cache directory.
from fars_cleaner import FARSFetcher
# Prepare for FARS file download, using the OS cache directory.
fetcher = FARSFetcher()
Suggested usage is to download files to a data directory in your current project directory.
Passing project_dir
will download files to project_dir/data/fars
by default. This behavior can be
overridden by setting cache_path
as well. Setting cache_path
alone provides a direct path to the directory
you want to download files into.
from pathlib import Path
from fars_cleaner import FARSFetcher
SOME_PATH = Path("/YOUR/PROJECT/PATH")
# Prepare to download to /YOUR/PROJECT/PATH/data/fars
# This is the recommended usage.
fetcher = FARSFetcher(project_dir=SOME_PATH)
# Prepare to download to /YOUR/PROJECT/PATH/fars
cache_path = "fars"
fetcher = FARSFetcher(project_dir=SOME_PATH, cache_path=cache_path)
cache_path = Path("/SOME/TARGET/DIRECTORY")
# Prepare to download directly to a specific directory.
fetcher = FARSFetcher(cache_path=cache_path)
Files can be downloaded in their entirety (data from 1975-2018), as a single year, or across a specified year range.
Downloading all of the data can be quite time consuming. The download will simultaneously unzip the folders, and delete
the zip files. Each zipped file will be unzipped and saved in a folder {YEAR}.unzip
# Fetch all data
fetcher.fetch_all()
# Fetch a single year
fetcher.fetch_single(1984)
# Fetch data in a year range (inclusive).
fetcher.fetch_subset(1999, 2007)
Processing FARS data
import fars_cleaner
#foobar.pluralize('word') # returns 'words'
#foobar.pluralize('goose') # returns 'geese'
#foobar.singularize('phenomena') # returns 'phenomenon'
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for fars_cleaner-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71a5294f7988121284fb88653cd1a4967cefb5c3b9d8173ef5c920fb3848d5cf |
|
MD5 | c49476dfe11783091b43b02e708a5b57 |
|
BLAKE2b-256 | 9d112e81e82491875a238fdd123c5ecdb619ba33b08ca61b9efecaa2e5cce06b |