<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def select_grid_model_residential(lvgd):
 """Selects typified model grid based on population Parameters lvgd : LVGridDistrictDing0 Low-voltage grid district object Returns ------- :pandas:`pandas.DataFrame<dataframe>` Selected string of typified model grid :pandas:`pandas.DataFrame<dataframe>` Parameters of chosen Transformer Notes ----- In total 196 distinct LV grid topologies are available that are chosen by population in the LV grid district. Population is translated to number of house branches. Each grid model fits a number of house branches. If this number exceeds 196, still the grid topology of 196 house branches is used. The peak load of the LV grid district is uniformly distributed across house branches. """


    # Load properties of LV typified model grids
    string_properties = lvgd.lv_grid.network.static_data['LV_model_grids_strings']
    # Load relational table of apartment count and strings of model grid
    apartment_string = lvgd.lv_grid.network.static_data[
        'LV_model_grids_strings_per_grid']

    # load assumtions
    apartment_house_branch_ratio = cfg_ding0.get("assumptions",
                                                 "apartment_house_branch_ratio")
    population_per_apartment = cfg_ding0.get("assumptions",
                                             "population_per_apartment")

    # calc count of apartments to select string types
    apartments = round(lvgd.population / population_per_apartment)

    if apartments > 196:
        apartments = 196

    # select set of strings that represent one type of model grid
    strings = apartment_string.loc[apartments]
    selected_strings = [int(s) for s in strings[strings >= 1].index.tolist()]

    # slice dataframe of string parameters
    selected_strings_df = string_properties.loc[selected_strings]

    # add number of occurences of each branch to df
    occurence_selector = [str(i) for i in selected_strings]
    selected_strings_df['occurence'] = strings.loc[occurence_selector].tolist()

    return selected_strings_df