'How to add a dollar sign to a seaborn heatmap

I have the following code that generates a Heatmap in Pandas:

def create_cohort(cohort_size,retention_matrix,titulo):
    print(f"{titulo}\n")

    with sns.axes_style("white"):
        fig, ax = plt.subplots(1, 2, figsize=(12, 8), sharey=True, gridspec_kw={'width_ratios': [1, 11]})
        
        # retention matrix
        sns.heatmap(retention_matrix, 
                    mask=retention_matrix.isnull(), 
                    annot=True, 
                    fmt='.0%', 
                    cmap='Purples', 
                    ax=ax[1])
        ax[1].set_title(f'Cohort: {titulo}', fontsize=16)
        ax[1].set(xlabel='Meses',
                  ylabel='')

        # cohort size
        cohort_size_df = pd.DataFrame(cohort_size).rename(columns={0: 'Tamanho da cohort'})
        white_cmap = mcolors.ListedColormap(['white'])
        sns.heatmap(cohort_size_df, 
                    annot=True, 
                    cbar=False, 
                    fmt='.0f', 
                    cmap=white_cmap, 
                    ax=ax[0])

        fig.tight_layout()
        
        return

This is a example of graph:

Heatmap

I would like to change the format of the most left table to add '$' before the number. I know I have to change the fmt='.0f', but I do not know how. I also could not find documentation on the values I can pass in the fmt parameter. Can someone also explain to me how this works? What values can I use?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source