如何在python中绘制图表使用

问题描述 投票:0回答:1

我有一个CSV文件客户:

-------------------------------------------
index | age_group | female | male | total |
-------------------------------------------
  0       16-20       23      5      28   |
  1       20-26       66      12     78   |
  2       26-32       12      3      15   |
 ...       ...        ..     ...     ..   |
-------------------------------------------

我想制作一个图表以显示年龄组与总数之间的关系,并制作一个图表以显示不同性别与总数之间的关系。

pandas matplotlib data-visualization
1个回答
2
投票

我用大熊猫作画。

import pandas as pd

# Barchart to show the relationship between age group and total
df.plot.bar(x='age_group', y='total', rot=0)

# Barchart to show the relationship between different gender and total
df.plot.bar(x='age_group', y=['female', 'male'], rot=0)
© www.soinside.com 2019 - 2024. All rights reserved.