pycancensus.parent_census_vectors

pycancensus.parent_census_vectors(vectors: str | List[str] | DataFrame, dataset: str | None = None, use_cache: bool = True, api_key: str | None = None) DataFrame[source]

Get all parent vectors up the hierarchy for given vectors.

Traverses the full vector hierarchy upward (matching R cancensus), returning every ancestor of the input vectors, not just direct parents.

Parameters:
  • vectors (str, list of str, or pd.DataFrame) – Vector IDs to find parents for, or a DataFrame as returned by list_census_vectors() with a ‘vector’ column

  • dataset (str, optional) – Dataset to search in. If None, inferred from vectors; all input vectors must then belong to the same dataset

  • use_cache (bool, default True) – Whether to use cached data if available

  • api_key (str, optional) – API key for CensusMapper API

Returns:

DataFrame with ancestor vector information, in discovery order (direct parents first, then grandparents, and so on)

Return type:

pd.DataFrame