表格如下:
问题: 对于主题物理学,在所有被归类为误差在0-10%范围内的案例中,返回学生百分比大于或等于BSchool1(基准)中95%的学生百分比,错误范围是0-10%和学科物理。
[IN]
import pandas as pd
data = [['B1', 'Grade_physics', '0-10%', 70],['B1', 'Grade_physics', '10-20%', 5],['B1', 'Grade_physics', '20-30%', 25],['B1', 'Grade_Maths', '10-20%', 20],['B1', 'Grade_Maths', '0-10%', 60],['B1', 'Grade_Maths', '20-30%',20 ],['B2', 'Grade_Maths', '0-10%', 50],['B2', 'Grade_Maths', '10-20%', 15],['B2', 'Grade_Maths', '20-30%', 35],['B2', 'Grade_physics', '10-20%', 30],['B2', 'Grade_physics', '0-10%', 60],['B2', 'Grade_physics', '20-30%',10 ]]
df = pd.DataFrame(data, columns = ['BSchool Name', 'Graded in','Error Bucket','Stu_perc'])
df
[OUT]
BSchool Name Graded in Error Bucket Stu_perc
0 B1 Grade_physics 0-10% 70
1 B1 Grade_physics 10-20% 5
2 B1 Grade_physics 20-30% 25
3 B1 Grade_Maths 10-20% 20
4 B1 Grade_Maths 0-10% 60
5 B1 Grade_Maths 20-30% 20
6 B2 Grade_Maths 0-10% 50
7 B2 Grade_Maths 10-20% 15
8 B2 Grade_Maths 20-30% 35
9 B2 Grade_physics 10-20% 30
10 B2 Grade_physics 0-10% 60
11 B2 Grade_physics 20-30% 10
[IN]:
#Subset of values where error bucket and subject are sliced
filter1 = df['Graded in'].str.contains('Grade_physics')
filter2=df['Error Bucket'].str.contains('0-10%')
df2 = df[filter1 & filter2]
#Compare the value of student percentage in sliced data to benchmark value
#(in this case student percentage in BSchool1)
filter3 = df2['BSchool Name'].str.contains('B1')
benchmark_value = df2[filter3]['Stu_perc']
df['Qualifyinglist']=(df2[['Stu_perc']]>=0.95*benchmark_value)
[OUT]:
ValueError: Wrong number of items passed 2, placement implies 1
[IN]:
df['Qualifyinglist']=(df2['Stu_perc']>=0.95*benchmark_value)
[OUT]:
ValueError: Can only compare identically-labeled Series objects
我要做什么:
我们与B学校有合作关系,我们正在尝试预测每个B学校中学生的整体成绩。然后,我们尝试根据0-10%,10-20%等类别对预测不准确的情况进行分类。例如,对于商学院物理1,正确地识别了70%的情况,错误范围从0-在BSchool 1中,有10%,5%的案例预测的物理学误差在10-20%范围内,依此类推。我们在B学校1中的模型很成功。因此,我们希望看到我们现在可以定位到所有B学校。
但是我遇到了如上所述的错误。
Value Error:Wrong number of items passed 2, placement implies 1这对我没有帮助。请帮助
答案 0 :(得分:0)
val=benchmark_value.iat[0]
df['Qualifyinglist']=df2['Stu_perc'].where(df2['Stu_perc']>=0.95*val)
这对我有用。