import re


def _df_to_dict(t, prefix='', d=None):
    """Convert a table to a dict.

    Arguments:
        t (pd.DataFrame): table
        prefix (str): string to prefix to each column name
        d (dict): a dictionary to insert keys into
    """

    if d is None:
        d = {}

    if prefix is not '':
        prefix = prefix + '_'

    re_paren = re.compile(r' *\(.*\)')
    for c in t.columns:
        c_name = prefix + re.sub(re_paren, '', c).replace(' ', '_')
        try:
            v = float(t[c][0])
        except ValueError:
            v = t[c][0]
        d[c_name] = v

    return(d)