def rows_to_dict(
    rows,
    main_key_position=0,
    null_value="delete",
    header_line=0,
    contains_open_ends=False,
):
    """
    Convert a row of rows (e.g. csv) to dictionary

    Parameters
    ----------
    rows : list
        the row based data to convert to `dict`
    main_key_position : int, optional
        if the main_key is not on the top left, its position can be specified
    null_value : any, optional
        if an emtpy field in the lists shall be represented somehow in the dictionary
    header_line : int, optional
        if the header_line is not the first one, its position can be specified
    contains_open_ends : bool, optional
        if each row is not in the same length (due to last set entry as last element in row),
        a length check for corrupted data can be ignored

    Returns
    -------
    dict
        dictionary containing the information from row-based data

    """
    data = dict()
    header = rows[header_line]

    for row in rows[header_line + 1 :]:
        sub_data = dict()
        for i in range(len(header)):
            if i == main_key_position:
                continue
            elif i >= len(row):
                if not contains_open_ends:
                    raise IndexError("not all elements are the same length")
                elif null_value != "delete":
                    sub_data[header[i]] = null_value
            elif not row[i] and null_value != "delete":
                sub_data[header[i]] = null_value
            elif not row[i]:
                continue
            else:
                sub_data[header[i]] = row[i]

        data[row[main_key_position]] = sub_data

    data = {header[main_key_position]: data}

    return data