The Census of Agriculture is a complete count of U.S. farms and ranches and the people who operate them. Census is conducted USDA NASS (National Agricultural Statistics Service) every 5 years, and the most recently available is 2017.
QuickStats provides browser interface and also API or FTP for programmatic or bulk download of 2002, 2007, 2012 and 2017 data.
Schema
list of dataset fields
Code
for f in get_schema():print('----')print(f.name)print(f.metadata[b'desc'].decode())
----
SOURCE_DESC
Source of data (CENSUS or SURVEY). Census program includes the Census of Ag as well as follow up projects. Survey program includes national, state, and county surveys.
----
SECTOR_DESC
Five high level, broad categories useful to narrow down choices (Crops, Animals & Products, Economics, Demographics, and Environmental).
----
GROUP_DESC
Subsets within sector (e.g., under sector = Crops, the groups are Field Crops, Fruit & Tree Nuts, Horticulture, and Vegetables).
----
COMMODITY_DESC
The primary subject of interest (e.g., CORN, CATTLE, LABOR, TRACTORS, OPERATORS).
----
CLASS_DESC
Generally a physical attribute (e.g., variety, size, color, gender) of the commodity.
----
PRODN_PRACTICE_DESC
A method of production or action taken on the commodity (e.g., IRRIGATED, ORGANIC, ON FEED).
----
UTIL_PRACTICE_DESC
Utilizations (e.g., GRAIN, FROZEN, SLAUGHTER) or marketing channels (e.g., FRESH MARKET, PROCESSING, RETAIL).
----
STATISTICCAT_DESC
The aspect of a commodity being measured (e.g., AREA HARVESTED, PRICE RECEIVED, INVENTORY, SALES).
----
UNIT_DESC
The unit associated with the statistic category (e.g., ACRES, $ / LB, HEAD, $, OPERATIONS).
----
SHORT_DESC
A concatenation of six columns: commodity_desc, class_desc, prodn_practice_desc, util_practice_desc, statisticcat_desc, and unit_desc.
----
DOMAIN_DESC
Generally another characteristic of operations that produce a particular commodity (e.g., ECONOMIC CLASS, AREA OPERATED, NAICS CLASSIFICATION, SALES). For chemical usage data, the domain describes the type of chemical applied to the commodity. The domain = TOTAL will have no further breakouts; i.e., the data value pertains completely to the short_desc.
----
DOMAINCAT_DESC
Categories or partitions within a domain (e.g., under domain = Sales, domain categories include $1,000 TO $9,999, $10,000 TO $19,999, etc).
----
AGG_LEVEL_DESC
Aggregation level or geographic granularity of the data (e.g., State, Ag District, County, Region, Zip Code).
----
STATE_ANSI
American National Standards Institute (ANSI) standard 2-digit state codes.
----
STATE_FIPS_CODE
NASS 2-digit state codes; include 99 and 98 for US TOTAL and OTHER STATES, respectively; otherwise match ANSI codes.
----
STATE_ALPHA
State abbreviation, 2-character alpha code.
----
STATE_NAME
State full name.
----
ASD_CODE
NASS defined county groups, unique within a state, 2-digit ag statistics district code.
----
ASD_DESC
Ag statistics district name.
----
COUNTY_ANSI
ANSI standard 3-digit county codes.
----
COUNTY_CODE
NASS 3-digit county codes; includes 998 for OTHER (COMBINED) COUNTIES and Alaska county codes; otherwise match ANSI codes.
----
COUNTY_NAME
County name.
----
REGION_DESC
NASS defined geographic entities not readily defined by other standard geographic levels. A region can be a less than a state (Sub-State) or a group of states (Multi-State), and may be specific to a commodity.
----
ZIP_5
US Postal Service 5-digit zip code.
----
WATERSHED_CODE
US Geological Survey (USGS) 8-digit Hydrologic Unit Code (HUC) for watersheds.
----
WATERSHED_DESC
Name assigned to the HUC.
----
CONGR_DISTRICT_CODE
US Congressional District 2-digit code.
----
COUNTRY_CODE
US Census Bureau, Foreign Trade Division 4-digit country code, as of April, 2007.
----
COUNTRY_NAME
Country name.
----
LOCATION_DESC
Full description for the location dimension.
----
YEAR
The numeric year of the data.
----
FREQ_DESC
Length of time covered (Annual, Season, Monthly, Weekly, Point in Time). Monthly often covers more than one month. Point in Time is as of a particular day.
----
BEGIN_CODE
If applicable, a 2-digit code corresponding to the beginning of the reference period (e.g., for freq_desc = Monthly, begin_code ranges from 01 (January) to 12 (December)).
----
END_CODE
If applicable, a 2-digit code corresponding to the end of the reference period (e.g., the reference period of Jan thru Mar will have begin_code = 01 and end_code = 03).
----
REFERENCE_PERIOD_DESC
The specific time frame, within a freq_desc.
----
WEEK_ENDING
Week ending date, used when freq_desc = Weekly.
----
LOAD_TIME
Date and time indicating when record was inserted into Quick Stats database.
----
VALUE
Published data value or suppression reason code.
----
VALUE_F
VALUE flag: NUM, (D) or (Z)
----
CV_%
Coefficient of variation. Available for the 2012 Census of Agriculture only. County-level CVs are generalized.
----
CV_%_F
CV_% flag: NUM, (H), (D) or (L)
Load dataset
Use get_df() function to load dataset as pandas dataframe. filters argument should be used to create queries using list of filters formatted as documented for pyarrow filters here.
Example: hired and contract labor
This example shows how usage of contract and hired labor, measured as percentage of farm expenses, changed over time in California and Wisconsin.
This more detailed example shows how to retrieve state-level values of farm sales by commodity type. In the map below color indicates commodity with the highest amount of sales. Hover over states to view full list of sales.
Code
# load relevant subset of the datasetdf = get_df(years=[2017], cols=['COMMODITY_DESC', 'SHORT_DESC', 'STATE_FIPS_CODE', 'VALUE'], filters=[('DOMAIN_DESC', '==', 'TOTAL'), ('STATISTICCAT_DESC', '==', 'SALES'), ('UNIT_DESC', '==', '$'), ('AGG_LEVEL_DESC', '==', 'STATE')])# select sales items to reportsales_items = [# 'COMMODITY TOTALS - SALES, MEASURED IN $',# 'CROP TOTALS - SALES, MEASURED IN $',# 'GRAIN - SALES, MEASURED IN $', 'CORN - SALES, MEASURED IN $','WHEAT - SALES, MEASURED IN $','SOYBEANS - SALES, MEASURED IN $','SORGHUM - SALES, MEASURED IN $','BARLEY - SALES, MEASURED IN $','RICE - SALES, MEASURED IN $','GRAIN, OTHER - SALES, MEASURED IN $','TOBACCO - SALES, MEASURED IN $','COTTON, LINT & SEED - SALES, MEASURED IN $','VEGETABLE TOTALS, INCL SEEDS & TRANSPLANTS, IN THE OPEN - SALES, MEASURED IN $','FRUIT & TREE NUT TOTALS - SALES, MEASURED IN $',# 'FRUIT & TREE NUT TOTALS, (EXCL BERRIES) - SALES, MEASURED IN $',# 'BERRY TOTALS - SALES, MEASURED IN $','HORTICULTURE TOTALS, (EXCL CUT TREES & VEGETABLE SEEDS & TRANSPLANTS) - SALES, MEASURED IN $','CUT CHRISTMAS TREES & SHORT TERM WOODY CROPS - SALES, MEASURED IN $',# 'CUT CHRISTMAS TREES - SALES, MEASURED IN $',# 'SHORT TERM WOODY CROPS - SALES, MEASURED IN $','FIELD CROPS, OTHER, INCL HAY - SALES, MEASURED IN $',# 'MAPLE SYRUP - SALES, MEASURED IN $',# 'ANIMAL TOTALS, INCL PRODUCTS - SALES, MEASURED IN $','POULTRY TOTALS, INCL EGGS - SALES, MEASURED IN $','CATTLE, INCL CALVES - SALES, MEASURED IN $','MILK - SALES, MEASURED IN $', 'HOGS - SALES, MEASURED IN $','SHEEP & GOATS TOTALS, INCL WOOL & MOHAIR & MILK - SALES, MEASURED IN $','EQUINE, (HORSES & PONIES) & (MULES & BURROS & DONKEYS) - SALES, MEASURED IN $','AQUACULTURE TOTALS - SALES & DISTRIBUTION, MEASURED IN $''SPECIALTY ANIMAL TOTALS, (EXCL EQUINE) - SALES, MEASURED IN $',]df = df.query('SHORT_DESC.isin(@sales_items)')df['COMMODITY_DESC'] = df['COMMODITY_DESC'].str.replace(' TOTALS', '')df_sales = df# state shapes for mappingfrom pubdata import geographydf = geography.get_state_df(scale='20m')\ .query('CONTIGUOUS')\ .rename(columns={'CODE': 'STATE_FIPS_CODE', 'NAME': 'STATE'})\ [['STATE_FIPS_CODE', 'STATE', 'geometry']]# top sales commodity for coloringd = df_sales.sort_values('VALUE', ascending=False)\ .groupby('STATE_FIPS_CODE')\ .first()\ .rename(columns={'COMMODITY_DESC': 'TOP_SALES_COMMODITY'})\ .reset_index()\ [['STATE_FIPS_CODE', 'TOP_SALES_COMMODITY']]df = df.merge(d, how='left', on='STATE_FIPS_CODE')# commodity sales for popupsd = df_sales.set_index(['STATE_FIPS_CODE', 'COMMODITY_DESC'])['VALUE']d /=1000d = d.unstack().reset_index()df = df.merge(d, how='left', on='STATE_FIPS_CODE')# display interactive mapdf.explore(column='TOP_SALES_COMMODITY', tiles='CartoDB positron')
Make this Notebook Trusted to load map: File -> Trust Notebook