def object_as_category(df_data):
    """
    dataframe object to category
    :param df_data:
    :return:
    """
    for col in df_data.columns:
        if df_data[col].dtype != 'object':
            continue
        num_unique_values = len(df_data[col].unique())
        num_total_values = len(df_data[col])
        if not num_total_values:
            return df_data
        if num_unique_values / num_total_values < 0.5:
            df_data.loc[:, (col)] = df_data[col].astype('category')
    return df_data
