def clean_table(df, id_column_name=None, id_prefix=''):

    """
    Cleans up a dataframe by setting all text to lower case and
    replacing spaces in column titles with underscores;
    can also create a new id column (supposed to be used as the key).

    Parameters
    ----------
    df (DataFrame):
        Dataframe to be cleaned
    id_column_name (str):
        Name of the id column (if None, then no new column is created)
    id_prefix (str):
        Prefix to add to the id number

    Returns:
    --------
    df (DataFrame):
        Cleaned dataframe
    """

    # Create a new column with IDs
    if id_column_name:
        df[id_column_name] = df.index.values
        df[id_column_name] = df[id_column_name].apply(lambda x: id_prefix + str(x))

    # Clean column names
    df.columns = df.columns.str.replace(' ', '_')
    df.columns = df.columns.str.lower()

    # Clean column text
    for col in df.columns:
        if df[col].dtype == 'object':
            df[col] = df[col].str.lower()

    return df