ebm.model.building_category module
- class MyEnumType(cls, bases, classdict, *, boundary=None, _simple=False, **kwds)[source]
Bases:
EnumType
- class BuildingCategory(value)[source]
Bases:
StrEnum- HOUSE = 'house'
- APARTMENT_BLOCK = 'apartment_block'
- KINDERGARTEN = 'kindergarten'
- SCHOOL = 'school'
- UNIVERSITY = 'university'
- OFFICE = 'office'
- RETAIL = 'retail'
- HOTEL = 'hotel'
- HOSPITAL = 'hospital'
- NURSING_HOME = 'nursing_home'
- CULTURE = 'culture'
- SPORTS = 'sports'
- STORAGE = 'storage_repairs'
- static from_string(category_name: str) BuildingCategory[source]
Create an enum object from category name :param category_name: :type category_name: str
- Returns:
building_category (BuildingCategory (Enum))
- Raises:
ValueError – category_name not found in BuildingCategory
- from_norsk(norsk: str) BuildingCategory[source]
- expand_building_category(row: Series) DataFrame[source]
Expand a row of data based on the building category into multiple rows, each representing a specific sub-category of either residential or non-residential buildings.
Parameters
- rowpd.Series
A pandas Series containing the data for a single row, including a ‘building_category’ field.
Returns
- pd.DataFrame
A DataFrame with expanded rows for each sub-category of the building category.
- expand_building_categories(df: DataFrame, unique_columns: List[str] = None)[source]
Transform input dataframe so that building_category within groups (residential/non-residential) are unpacked into all containing categories. Duplicates categories are removed. Specific categories with values area preferred over category groups when there is a conflict.
Parameters
df : pandas.core.frame.DataFrame unique_columns : str
list of column names that should be treated as joint unique. default: [‘building_category’]
Returns
pandas.core.frame.DataFrame
- collapse_building_category(building_category: Series) Series[source]
Replace building category labels with building group labels where appropriate.
This function takes a pandas Series containing building category strings separated by either “+” or “,”. It normalizes token case, applies a set of category‑collapse rules, and returns a new Series with collapsed category labels.
- building groups implemented:
- residential
house, apartment_block
- non_residential
culture, hospital, hotel, kindergarten, nursing_home, office, retail, school, sports, storage_repairs, university
- default
All of the above
Parameters
- building_categorypd.Series
- Series of building category strings. Each value must be a
string containing tokens separated by either
"+"or “,”`. Tokens may contain arbitrary casing; they are normalized to lowercase.
Returns
- pd.Series
series with building categories collapsed into groups
Examples
>>> import pandas as pd >>> collapse_building_category(pd.Series(["house+apartment_block"])) 0 residential dtype: object
>>> collapse_building_category(pd.Series( ... ["culture+hospital+hotel+kindergarten+nursing_home+office+retail" ... "+school+sports+storage_repairs+university"] ... )) 0 non_residential dtype: object