add_region
add_region(
data=None,
country=None,
region_to='region',
subregion=False,
quiet=False,
)Add region (and subregion) columns from a country column.
The data-frame-friendly form of recode_region(): point it at an existing country column and it appends a region column (named via region_to) and, optionally, a subregion. Handy right after read_folder() to enrich raw exports before grouping by region. The lookup, matching and unmatched-country warning behave exactly as in recode_region().
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| data | pandas.DataFrame | A data frame. If omitted, the session default is used. | None |
| country | str | The country column. | None |
| region_to | str | Name of the region column to add. Defaults to “region”. | 'region' |
| subregion | bool | If True, also add a subregion column. Defaults to False. |
False |
| quiet | bool | Passed to recode_region(). |
False |
Returns
| Name | Type | Description |
|---|---|---|
| pandas.DataFrame | data with the new column(s) added. |
See Also
recode_region, country_region
Examples
>>> df = pd.DataFrame({"demo_country": ["Germany", "Japan", "Brazil"]})
>>> add_region(df, "demo_country", subregion=True)