noob
noob

Reputation: 3811

ValueError: Wrong number of items passed 2, placement implies 1

Table looks like :

Question: Out of all the cases classfied with error in range of 0-10% for subject Physics, return table of values where the student percentage is more than or equal to 95% of the student percentage in BSchool1 (benchmark) for error range 0-10% and subject Physics.

[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

What I am trying to do:

We have tie-ups with B-Schools and we are trying to predict the overall grade of students in each B-School. Then we are trying to classify the cases where the prediction was inaccurate based on buckets of 0-10% , 10-20% etc. For example for Physics for Business school 1, 70% cases were identified correctly with error in range from 0-10%, 5% cases prediction had error in range of 10-20% for physics in BSchool 1 and so on. Our model in B-School 1 was successful. So we wish to see which all B-Schools we can target now.

However I am getting error as shown above.

Value Error:Wrong number of items passed 2, placement implies 1 this didnt help me. Please help

Upvotes: 0

Views: 1624

Answers (1)

noob
noob

Reputation: 3811

val=benchmark_value.iat[0]

df['Qualifyinglist']=df2['Stu_perc'].where(df2['Stu_perc']>=0.95*val)

This worked for me.

Upvotes: 1

Related Questions