# Wrong order in 5.Improve the Layout and Ordering

Hi,

out of curosity and to refresh my recently learned skills, i’ve tried to compute the order of the decreasing ending gender gap-values myself. I’ve come to a different solution than you. My solution ranks Physical Sciences behind Biology.

https://app.dataquest.io/m/148/color%2C-layout%2C-and-annotations/5/improve-the-layout-and-ordering

My Code:

``````    org_stem_cats = ['Math and Statistics', 'Computer Science', 'Engineering', 'Biology', 'Physical Sciences', 'Psychology']
print((100-women_degrees[org_stem_cats].iloc-women_degrees[org_stem_cats].iloc).abs().sort_values(ascending=False))

``````
``````    Engineering 65.000000
Computer Science 63.600000
Psychology 53.400000
Physical Sciences 19.800000
Biology 17.484794
Math and Statistics 13.800000
Name: 41, dtype: float64
``````

Greetings

Sebastian

Can you explain, in words, what exactly are you trying to do in this line of code and how it relates to that particular Mission Step?

Also, `women_degrees[org_stem_cats].iloc-women_degrees[org_stem_cats].iloc` would return `0.0` for every category, so you might have shared an incorrect code?

1 Like

You’re right, i was a bit short in my explanation, (and it’s a bit nitpicky to check if the given order is correct )

`women_degrees[org_stem_cats].iloc` returns a Series for the last year in the dataset (the 42nd row) for the 6 stem degrees:

``````Math and Statistics    43.100000
Computer Science       18.200000
Engineering            17.500000
Biology                58.742397
Physical Sciences      40.100000
Psychology             76.700000
Name: 41, dtype: float64
``````

`100-women_degrees[org_stem_cats].iloc` returns the inverse, so the share of men in the stem degrees.

``````Math and Statistics    56.900000
Computer Science       81.800000
Engineering            82.500000
Biology                41.257603
Physical Sciences      59.900000
Psychology             23.300000
Name: 41, dtype: float64
``````

These two subtracted is the difference between men and women (the gender gap) in each of these degrees in the last year:

``````Math and Statistics    13.800000
Computer Science       63.600000
Engineering            65.000000
Biology               -17.484794
Physical Sciences      19.800000
Psychology            -53.400000
Name: 41, dtype: float64
``````

Since we’re only interested in the absolute differences between men and women, i used the abs() function to do that:

``````(100-women_degrees[org_stem_cats].iloc-women_degrees[org_stem_cats].iloc).abs()

Math and Statistics    13.800000
Computer Science       63.600000
Engineering            65.000000
Biology                17.484794
Physical Sciences      19.800000
Psychology             53.400000
Name: 41, dtype: float64
``````

The last step is to order the values in a descending order:

``````(100-women_degrees[org_stem_cats].iloc-women_degrees[org_stem_cats].iloc).abs().sort_values(ascending=False)

Engineering            65.000000
Computer Science       63.600000
Psychology             53.400000
Physical Sciences      19.800000
Biology                17.484794
Math and Statistics    13.800000
Name: 41, dtype: float64
``````

Then you can use this Series as an index in the same way as the given stem_cats list.

``````org_stem_cats = ['Math and Statistics', 'Computer Science', 'Engineering', 'Biology', 'Physical Sciences', 'Psychology']

stem_cats = (100-women_degrees[org_stem_cats].iloc-women_degrees[org_stem_cats].iloc).abs().sort_values(ascending=False).index

fig = plt.figure(figsize=(18, 3))

for sp in range(0,6):
ax.plot(women_degrees['Year'], women_degrees[stem_cats[sp]], c=cb_dark_blue, label='Women', linewidth=3)
ax.plot(women_degrees['Year'], 100-women_degrees[stem_cats[sp]], c=cb_orange, label='Men', linewidth=3)
for key,spine in ax.spines.items():
spine.set_visible(False)
ax.set_xlim(1968, 2011)
ax.set_ylim(0,100)
ax.set_title(stem_cats[sp])
ax.tick_params(bottom="off", top="off", left="off", right="off")

plt.show()
``````

My order:

The expected order:

1 Like

As far as I can tell, your approach and thought process is correct.

It seems when they created this particular Mission Step, they ended up relying on a visual check.

Either way, you should report this to them using the `Contact Us` button in the top-right of this page. Share the link to your reply above as well so that they have the details.