'Convert Dataframe into Series to return directly the value in that row and column

I'm trying to convert a DF I have, so that it can return true a piece of code like this (cat_totals being a df):

assert_equal(cat_totals["Interdisciplinary"],12296)
assert_equal(cat_totals["Engineering"],537583)

For this, I'm supposed to filter the main dataframe (df) into a subset containing only the Subject and the Total number of students. Then I group by the subject (Major_category) and sum. The numbers are correct in my dataframe, but if I try to run the above code, it throws up an error. How can I convert the dataframe so that the above assert_equals returns True?

cat_totals = df[['Major_category', 'Total']]
cat_totals = cat_totals.groupby(['Major_category']).sum()
cat_totals['Total'] = cat_totals['Total'].astype(int)
display(cat_totals.head(10))

This is the output of the above code and what the data looks like.

With this the DF looks intuitively correct, but cat_totals['Interdisciplinary'] does not equal the value I'm looking for. In the table, the number that corresponds to the Major is correct, so the calculation is correct, but the format of the return value does not seem right.

Any help would be much appreciated! I'm quite new to working with Pandas, so it's a bit of a struggle.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source