Sets index names to 'index' for regular, or 'level_x' for Multi

def set_default_names(data):
    """Sets index names to 'index' for regular, or 'level_x' for Multi"""
    if all(name is not None for name in data.index.names):
        return data

    data = data.copy()
    if data.index.nlevels > 1:
        names = [name if name is not None else 'level_{}'.format(i)
                 for i, name in enumerate(data.index.names)]
        data.index.names = names
    else:
        data.index.name = data.index.name or 'index'
    return data