<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_dim_label(js_dict, dim, input="dataset"):
 """Get label from a given dimension. Args: js_dict (dict):
 dictionary containing dataset data and metadata. dim (string):
 dimension name obtained from JSON file. Returns: dim_label(pandas.DataFrame):
 DataFrame with label-based dimension data. """


    if input == 'dataset':
        input = js_dict['dimension'][dim]
        label_col = 'label'
    elif input == 'dimension':
        label_col = js_dict['label']
        input = js_dict
    else:
        raise ValueError

    try:
        dim_label = input['category']['label']

    except KeyError:
        dim_index = get_dim_index(js_dict, dim)
        dim_label = pd.concat([dim_index['id'],
                               dim_index['id']],
                              axis=1)
        dim_label.columns = ['id', 'label']
    else:
        dim_label = pd.DataFrame(list(zip(dim_label.keys(),
                                          dim_label.values())),
                                 index=dim_label.keys(),
                                 columns=['id', label_col])
    # index must be added to dim label so that it can be sorted
    try:
        dim_index = input['category']['index']
    except KeyError:
        dim_index = pd.DataFrame(list(zip([dim_label['id'][0]], [0])),
                                 index=[0],
                                 columns=['id', 'index'])
    else:
        if type(dim_index) is list:
            dim_index = pd.DataFrame(list(zip(dim_index,
                                              range(0, len(dim_index)))),
                                     index=dim_index, columns=['id', 'index'])
        else:
            dim_index = pd.DataFrame(list(zip(dim_index.keys(),
                                              dim_index.values())),
                                     index=dim_index.keys(),
                                     columns=['id', 'index'])
    dim_label = pd.merge(dim_label, dim_index, on='id').sort_index(by='index')
    return dim_label