Skip to content

hbsir.api.add_attribute

Add attributes to table based on ID column.

This function takes a Pandas DataFrame containing a household ID column, and enriches it by adding columns indicating attributes like urban/rural status, province, county etc.

Parameters:

Name Type Description Default
table DataFrame

Input DataFrame containing the ID column.

required
name _Attribute

Name of attribute to add.

required
aspects list of str

Specific aspects of the attribute to add as columns.

"name"

Note

Supported attribute names are:

  • "Urban_Rural": Urban or rural status (aspects: "name", "farsi_name")
  • "Province": Province name (aspects: "name", "farsi_name")
  • "County": County name (aspects: "name", "farsi_name")

Other Parameters:

Name Type Description
column_names list of str

Custom names to use for the added columns.

id_col str

Name of the ID column in the table.

year_col str

Name of the year column in the table.

Returns:

Type Description
DataFrame

Input DataFrame with additional columns containing attribute values.

Examples:

import lfsir
table = lfsir.load_table(years=1401)
table = add_attribute(table, "Urban_Rural")
table = add_attribute(table, "Province", aspects="farsi_name")