def sanitize_dataframe(df):
    """Sanitize a DataFrame to prepare it for serialization.

    * Make a copy
    * Raise ValueError if it has a hierarchical index.
    * Convert categoricals to strings.
    * Convert np.int dtypes to Python int objects
    * Convert floats to objects and replace NaNs by None.
    * Convert DateTime dtypes into appropriate string representations
    """
    import pandas as pd
    import numpy as np
    df = df.copy()
    if isinstance(df.index, pd.core.index.MultiIndex):
        raise ValueError('Hierarchical indices not supported')
    if isinstance(df.columns, pd.core.index.MultiIndex):
        raise ValueError('Hierarchical indices not supported')
    for col_name, dtype in df.dtypes.iteritems():
        if str(dtype) == 'category':
            df[col_name] = df[col_name].astype(str)
        elif np.issubdtype(dtype, np.integer):
            df[col_name] = df[col_name].astype(object)
        elif np.issubdtype(dtype, np.floating):
            col = df[col_name].astype(object)
            df[col_name] = col.where(col.notnull(), None)
        elif str(dtype).startswith('datetime'):
            df[col_name] = df[col_name].astype(str).replace('NaT', '')
    return df
