def _reset_index(df, name=None):
    """Resets the index of the dataframe, optionally renaming the index."""

    if name is None:
        return df.reset_index()
    else:
        index_name = df.index.name or 'index'
        return df.reset_index().rename(columns={index_name: name})