def build_lv_graph_residential(lvgd, selected_string_df):
    """Builds nxGraph based on the LV grid model

    Parameters
    ----------
    lvgd : LVGridDistrictDing0
        Low-voltage grid district object
    selected_string_df: :pandas:`pandas.DataFrame<dataframe>`
        Table of strings of the selected grid model

    Notes
    -----
    To understand what is happening in this method a few data table columns
    are explained here

    * `count house branch`: number of houses connected to a string
    * `distance house branch`: distance on a string between two house branches
    * `string length`: total length of a string
    * `length house branch A|B`: cable from string to connection point of a house

    A|B in general brings some variation in to the typified model grid and
    refer to different length of house branches and different cable types
    respectively different cable widths.
    """

    houses_connected = (
        selected_string_df['occurence'] * selected_string_df[
            'count house branch']).sum()

    average_load = lvgd.peak_load_residential / \
                   houses_connected

    average_consumption = lvgd.sector_consumption_residential / \
                   houses_connected

    hh_branch = 0

    # iterate over each type of branch
    for i, row in selected_string_df.iterrows():

        # get overall count of branches to set unique branch_no
        branch_count_sum = len(list(
            lvgd.lv_grid._graph.neighbors(lvgd.lv_grid.station())))

        # iterate over it's occurences
        for branch_no in range(1, int(row['occurence']) + 1):

            hh_branch += 1
            # iterate over house branches
            for house_branch in range(1, row['count house branch'] + 1):
                if house_branch % 2 == 0:
                    variant = 'B'
                else:
                    variant = 'A'

                # cable distributor to divert from main branch
                lv_cable_dist = LVCableDistributorDing0(
                    grid=lvgd.lv_grid,
                    string_id=i,
                    branch_no=branch_no + branch_count_sum,
                    load_no=house_branch)
                # add lv_cable_dist to graph
                lvgd.lv_grid.add_cable_dist(lv_cable_dist)

                # cable distributor within building (to connect load+geno)
                lv_cable_dist_building = LVCableDistributorDing0(
                    grid=lvgd.lv_grid,
                    string_id=i,
                    branch_no=branch_no + branch_count_sum,
                    load_no=house_branch,
                    in_building=True)
                # add lv_cable_dist_building to graph
                lvgd.lv_grid.add_cable_dist(lv_cable_dist_building)

                lv_load = LVLoadDing0(grid=lvgd.lv_grid,
                                      string_id=i,
                                      branch_no=branch_no + branch_count_sum,
                                      load_no=house_branch,
                                      peak_load=average_load,
                                      consumption={
                                          'residential': average_consumption})

                # add lv_load to graph
                lvgd.lv_grid.add_load(lv_load)

                cable_name = row['cable type'] + \
                             ' 4x1x{}'.format(row['cable width'])
                cable_type = lvgd.lv_grid.network.static_data[
                    'LV_cables'].loc[cable_name]

                # connect current lv_cable_dist to station
                if house_branch == 1:
                    # edge connect first house branch in branch with the station
                    lvgd.lv_grid._graph.add_edge(
                        lvgd.lv_grid.station(),
                        lv_cable_dist,
                        branch=BranchDing0(
                            length=row['distance house branch'],
                            kind='cable',
                            type=cable_type,
                            id_db='branch_{sector}{branch}_{load}'.format(
                                branch=hh_branch,
                                load=house_branch,
                                sector='HH')
                        ))
                # connect current lv_cable_dist to last one
                else:
                    lvgd.lv_grid._graph.add_edge(
                        lvgd.lv_grid._cable_distributors[-4],
                        lv_cable_dist,
                        branch=BranchDing0(
                            length=row['distance house branch'],
                            kind='cable',
                            type=lvgd.lv_grid.network.static_data[
                                'LV_cables'].loc[cable_name],
                            id_db='branch_{sector}{branch}_{load}'.format(
                                branch=hh_branch,
                                load=house_branch,
                                sector='HH')))

                # connect house to cable distributor
                house_cable_name = row['cable type {}'.format(variant)] + \
                                   ' 4x1x{}'.format(
                                       row['cable width {}'.format(variant)])
                lvgd.lv_grid._graph.add_edge(
                    lv_cable_dist,
                    lv_cable_dist_building,
                    branch=BranchDing0(
                        length=row['length house branch {}'.format(
                            variant)],
                        kind='cable',
                        type=lvgd.lv_grid.network.static_data['LV_cables']. \
                            loc[house_cable_name],
                        id_db='branch_{sector}{branch}_{load}'.format(
                            branch=hh_branch,
                            load=house_branch,
                            sector='HH'))
                )

                lvgd.lv_grid._graph.add_edge(
                    lv_cable_dist_building,
                    lv_load,
                    branch=BranchDing0(
                        length=1,
                        kind='cable',
                        type=lvgd.lv_grid.network.static_data['LV_cables']. \
                            loc[house_cable_name],
                        id_db='branch_{sector}{branch}_{load}'.format(
                            branch=hh_branch,
                            load=house_branch,
                            sector='HH'))
                )