from tabulate import tabulate


def tableize(df, tablefmt="pretty", is_print=True):
    """
    Converts dataframe to a formatted table
    For more details, see https://pypi.org/project/tabulate/

    :param df: dataframe to save
    :type df: df object

    :param tablefmt: format of table
    :type tablefmt: string

    :param is_print: print to standard output?
    :type is_print: boolean
    """

    table = tabulate(
        df,
        headers="keys",
        tablefmt=tablefmt,
        showindex=True,
        stralign="center",
        numalign="center",
    )
    if is_print:
        print(table)
    return table