gpt4 book ai didi

pandas - python : Best way to visualize dict of dicts

转载 作者:行者123 更新时间:2023-12-02 14:59:51 26 4
gpt4 key购买 nike

我想可视化下面的字典

players_info = {'Afghanistan': {'Asghar Stanikzai': 809.0,
'Mohammad Nabi': 851.0,
'Mohammad Shahzad': 1713.0,
'Najibullah Zadran': 643.0,
'Samiullah Shenwari': 774.0},
'Australia': {'AJ Finch': 1082.0,
'CL White': 988.0,
'DA Warner': 1691.0,
'GJ Maxwell': 822.0,
'SR Watson': 1465.0},
'England': {'AD Hales': 1340.0,
'EJG Morgan': 1577.0,
'JC Buttler': 985.0,
'KP Pietersen': 1176.0,
'LJ Wright': 759.0}}

目前我正在使用以下方式,但使用大字典会造成困惑,这是我不希望的。

import pandas as pd
import matplotlib.pyplot as plt

pd.DataFrame(players_info).plot.bar()
plt.show()

请建议一种更好的可视化方法。谢谢

最佳答案

我建议使用 heatmap .

import pandas as pd
import seaborn as sns
sns.set(rc={"figure.figsize":(12,8)})

df = pd.DataFrame(players_info)
g = sns.heatmap(df, cmap="Blues", annot=True, fmt='g')
g.get_figure().savefig("heatmap.png")

输出: enter image description here

关于pandas - python : Best way to visualize dict of dicts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50614222/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com