pandas 按条件分组制图
如何以姓名为横坐标,分数为纵坐标,画 条形图?
回答:
試試
df.pivot('name', 'subject', 'score').plot.bar()
基本pandas 可視化原則是,使用pivot 或melt搞出製圖需要的表格格式。
下列是我跑的代碼(Jupyter Notebook)
% matplotlib inlinedata = [ {"name":"abc", "subject":"A", "score":40}, {"name":"abc", "subject":"B", "score":60}, {"name":"abc", "subject":"C", "score":40},
{"name":"xyz", "subject":"A", "score":10}, {"name":"xyz", "subject":"B", "score":90}, {"name":"xyz", "subject":"C", "score":30}]
df = pd.DataFrame(data)
df.pivot('name', 'subject', 'score').plot.bar()
結果:
以上是 pandas 按条件分组制图 的全部内容, 来源链接: utcz.com/a/163742.html