A python library that uses API interface to obtain USDA/NASS Quick Stat data
provides a simplified interface to access data from the USDA's Quick Stats API. The library is designed to fetch agricultural data, process it, and return it in a user-friendly format.
To use this library, you need Python installed on your machine. The library depends on requests
and pandas
andusda_stat
, which can be installed using pip:
pip install requests pandas
pip install usda_quickstats
Import the library into your Python script to start using its functionalities.
import usda_quickstats
First go to USDA/NASS Quick Stats to get API_KEY Then use KEY_init("your api key") to complete the configuration of API_KEY
The library offers the following primary functions:
get_data(params)
: Fetches specific data based on query parameters. Returns a pandas DataFrame.get_par(par)
: Returns possible values for a given column or header name in a DataFrame.get_counts(params)
: Retrieves the count of rows for queried data.
params = {"commodity_desc": "CORN", "year": 2020}
data = usda_quickstats.get_data(params)
print(data)
parameter_values = usda_quickstats.get_par("commodity_desc")
print(parameter_values)
params = {"commodity_desc": "CORN", "year": 2020}
count = usda_quickstats.get_counts(params)
print(f"Number of records: {count}")