Seaborn 热图货币格式 [英] Seaborn Heatmap Currency Format

查看:66
本文介绍了Seaborn 热图货币格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于以下热图:

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
%matplotlib inline
df = pd.DataFrame(
      {'A' : ['A', 'A', 'B', 'B','C', 'C', 'D', 'D'],
       'B' : ['A', 'B', 'A', 'B','A', 'B', 'A', 'B'],
       'C' : [22000, 4000, 500, 20000, 0, 3000, 90000, 1000],
       'D' : [6000, 62000, 7000, 700, 30000, 30, 1000, 1000]})

df=df.pivot('A','B','C')
fig, ax = plt.subplots(1, 1, figsize =(4,6))

sns.heatmap(df, annot=True, linewidths=0, cbar=False)
plt.show()

我希望这些值显示为以千计的货币,如下所示:22,000 美元

I would like the values to display as currency in thousands like this: $22K

奖励问题:显示为千位小数,如下所示:$8.9K

Bonus question: Display as thousands with one decimal like this: $8.9K

提前致谢!

推荐答案

df["C"] = df["C"].map(lambda x: "${:,.1f}".format(x/1000.))

这篇关于Seaborn 热图货币格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆