Pandas Python:可视化dict-of-dict的最佳方法

Pandas Python:可视化dict-of-dict的最佳方法,pandas,dataframe,matplotlib,data-visualization,seaborn,Pandas,Dataframe,Matplotlib,Data Visualization,Seaborn,我想想象一下下面的格言 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

我想想象一下下面的格言

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}}
目前我正在使用以下方法,但对于大型dict,它会造成我不想要的混乱

import pandas as pd
import matplotlib.pyplot as plt

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

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

您首先需要一个更好的dict数据帧结构

df = pd.DataFrame([(i,j,players_info[i][j]) for i in players_info.keys() for j in players_info[i].keys()], columns=["country", "player", "score"])
然后,您可以使用如下所示的绘图:

fig = plt.figure(figsize=(15,5))
ax = sns.barplot(x="player", y="score", hue="country" ,data=df)
plt.xticks(rotation=45)
plt.show()
输出:

我建议使用

输出:

您的问题的答案取决于您将如何使用数据。不幸的是,我担心你的问题完全是基于意见的。如果您准确地告诉我们您希望在数据或特定方法中强调什么,那么您更有可能吸引有用的回答。@jpp我试图绘制简单的条形图来分析每个国家的每个球员的得分差异,但正如我所说的,这会造成混乱,因此我想知道一种比使用条形图更好的方法。虽然这可能不是呈现结果的最佳方式,但接受这个答案的原因是,这肯定是一种不同于条形图的方式。任何其他方法也将不胜感激:)
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")