pycancensus.find_census_vectors¶
- pycancensus.find_census_vectors(query: str, dataset: str, type: str = 'all', query_type: str = 'exact', interactive: bool = False, use_cache: bool = True, quiet: bool = False, api_key: str | None = None) DataFrame[source]¶
Find census vectors using exact, semantic, or keyword search.
Mirrors R cancensus’s find_census_vectors(). Exact search matches the query literally against vector details. Semantic search tolerates spelling and phrasing differences via n-gram edit-distance matching. Keyword search splits the query into words and ranks vectors by how many of them match.
- Parameters:
query (str) – Search query.
dataset (str) – The dataset to search in (e.g., ‘CA16’).
type (str, default "all") – Filter by vector type: ‘all’, ‘total’, ‘male’, or ‘female’.
query_type (str, default "exact") – One of ‘exact’, ‘semantic’, or ‘keyword’.
interactive (bool, default False) – For keyword search: prompt to show lower-precision matches beyond the top-ranked results.
use_cache (bool, default True) – If True, uses cached vector list if available.
quiet (bool, default False) – When True, suppress messages and warnings.
api_key (str, optional) – API key for CensusMapper API.
- Returns:
Matching vectors with columns vector, type, label, details.
- Return type:
pd.DataFrame
Examples
>>> import pycancensus as pc >>> pc.find_census_vectors('Oji-cree', dataset='CA16', type='total') >>> pc.find_census_vectors('after tax income', 'CA16', query_type='semantic') >>> pc.find_census_vectors('commute duration', 'CA16', query_type='keyword')