【发布时间】:2020-12-12 14:47:31
【问题描述】:
这是我的代码,我不知道我做错了什么。没有错误,但是当我得到我的结果时,它并没有显示箱线图,只是一个 x 轴和一个带有数字的 y 轴。
import numpy as np
import matplotlib.pyplot as plt
#read in the dataset
data= np.genfromtxt("C:\\Users\\pearlyn\\Downloads\\education qualification.csv",
delimiter=',',
names=True, dtype=('U7','U10','U30','U4',int))
race = data[(data['mother_race']=='INDIAN')]
race_1 = race[race['birth_order']=='1st']
race_2= race_1[race_1['month']== '2019-12']
catA = race_2[race_2['mother_education'] == '"A" LEVEL/DIPLOMA']['birth_count']
catB = race_2[race_2['mother_education'] == '"N" LEVEL/"O" LEVEL']['birth_count']
catC = race_2[race_2['mother_education'] == 'NO QUALIFICATION']['birth_count']
catD = race_2[race_2['mother_education'] == 'PSLE']['birth_count']
catE = race_2[race_2['mother_education'] == 'UNIVERSITY DEGREE']['birth_count']
y_values = np.array([catA, catB, catC, catD, catE])
x_labels = np.unique(data['mother_education'])
plt.boxplot(y_values.transpose(),all(x_labels),patch_artist=True)
plt.show()
【问题讨论】:
-
所以,在回复your last question 时,人们告诉你他们不能说太多,因为他们没有你的输入数据。为什么你认为这与这里无关?
-
如何添加我的输入数据?
-
请为 minimal reproducible example 发布 csv 数据。很好奇,您为什么使用
numpy而不是pandas,后者更适合按列标识符运行逻辑过滤器? -
在文本编辑器中打开您的 csv 数据,并在此处复制/粘贴其内容的示例(足以重现问题),并在代码块内格式化。记住 csv 是一个文本文件。
标签: python numpy matplotlib