In calculating grades, I drop each student's two lowest homework scores. A sample dataframe is shown here:
df=pd.DataFrame([[10, 9, 10, 5, 7], [8, 7, 9, 9, 4], [10, 10, 7, 0, 8],
[5, 9, 7, 6, 3], [10, 5, 0, 8, 10], [8, 9, 10, 10, 10]],
columns=['HW1', 'HW2', 'HW3', 'HW4', 'HW5'],
index=['Aaron', 'Bridget', 'Charles', 'Donna', 'Evan', 'Francesca'])
df
The actual dataframe contains more columns than this (for tests, reports, etc.), but it's homework assignments where I need to find the two lowest scores for each record.
I want to add two columns in the dataframe, ['Lowest'] and ['Second_Lowest'], and indicate each student's lowest and second lowest scores, respectively, in those columns.
I tried the following code to get the lowest value, using the .min() method, but got an error:
df['Lowest_HW'] = df[['HW1', 'HW2', 'HW3', 'HW4', 'HW5']].min()
df.head()
So for Aaron, the value for Lowest will be 5 and Second_Lowest will be 7; for Francesca, Lowest will be 8 and Second_Lowest will be 9.
Apparently, the code for the .min() method isn't right, and I'm completely clueless about finding the second lowest value.
Any advice on how I might tackle these steps?