print(final)
OUTPUT:
intent sex age
2 Suicide F 21.0
3 Suicide M 60.0
4 Suicide M 64.0
5 Suicide M 31.0
7 Undetermined M 48.0
9 Accidental M 50.0
11 Suicide M 30.0
13 Suicide M 43.0
15 Homicide M 27.0
17 Suicide M 55.0
20 Suicide M 51.0
22 Suicide F 52.0
24 Suicide M 19.0
25 Homicide M 51.0
26 Homicide M 41.0
28 Suicide M 21.0
29 Suicide M 56.0
30 Homicide M 43.0
32 Suicide M 55.0
34 Suicide M 27.0
pro = final['intent'] == 'Suicide'
suicide_df = final[pro]
suicide_df.plot.bar('sex')
plt.ylabel('age')
plt.xlabel('sex')
plt.show()
因此,我最近刚开始使用Python学习一些数据科学的在线课程,现在我们正在学习Panadas库
我从一个csv死亡率文件中获取了一个数据集,现在它以熊猫数据框的形式出现,如上图所示
我希望将条形图按性别分类,这样只显示两个条形图(一个为男性,一个为女性),并指示每个条形图中有多少条死亡,而不是在所附的图像中如何显示。感谢您的指导。Graph of what displays so far
您可以尝试在} :
final
数据框中绘制sex列的^{您可以使用:
输出:
相关问题 更多 >
编程相关推荐