pycancensus.child_census_vectors

pycancensus.child_census_vectors(vectors: str | List[str] | DataFrame, dataset: str | None = None, use_cache: bool = True, api_key: str | None = None, leaves_only: bool = False, max_level: int | None = None, keep_parent: bool = False) DataFrame[source]

Get all child vectors down the hierarchy for given vectors.

Traverses the full vector hierarchy downward (matching R cancensus), returning every descendant of the input vectors, not just direct children.

Parameters:
  • vectors (str, list of str, or pd.DataFrame) – Parent vector IDs, 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

  • leaves_only (bool, default False) – Only return terminal vectors that themselves have no children

  • max_level (int, optional) – Maximum depth to traverse. Default traverses the full hierarchy; max_level=1 returns only direct children

  • keep_parent (bool, default False) – Also include the input vectors in the result

Returns:

DataFrame with descendant vector information, in discovery order (direct children first, then grandchildren, and so on)

Return type:

pd.DataFrame