Act fast, special offers end soon! Up to $294 is savings when you get Premium today.
Get offer codes

Visualizing Frequency Distributions

Screen Link:

My Code: <mport pandas as pd
wnba = pd.read_csv(‘wnba.csv’)

wnba[‘Experience’] = wnba[‘Experience’].replace(‘R’, ‘0’).astype(int)

def experience_labels(row):
if row == 0:
return ‘Rookie’
if ( 1 < row <= 3):
return ‘Litte experience’
if ( 4 < row <= 5):
return ‘Experienced’
if ( 5 < row <= 10):
return ‘Very experienced’
if row > 10:
return ‘Veteran’

wnba[‘Experience labels’] = wnba[‘Experience’].apply(experience_labels)
wnba[‘Experience labels’].value_counts().iloc[[3,0,2,1,4]]>

What I expected to happen:
I expect my code to reproduce the same results as required in dataquest

What actually happened:
My plot doesn’t look same as in Dataquest , thus I can’t progress

Replace this line with the output/error
One of your variables doesn’t seem to have the correct value. Please re-check the instructions and your code. * Your 1st plot doesn’t match what we expected.

Please make sure to appropriately format your code as indicated in the guidelines in this post - Guidelines for asking a technical question in our Community

Although I haven’t done this lesson yet, I tried playing around with your code and compared it to the solution provided for this screen and discovered a few things.

First, we do not need to create our own function here in order to label the players based on their years of experience; this step has been done for us and the labels are stored in wnba['Exp_ordinal']. Therefore, we can progress to the next screen by simply plotting the data using wnba['Exp_ordinal'] without having to define the function experience_labels().

That said, if you want your function to work, consider the following:
What label would your function (experience_labels()) give a player if

  • they had 1 year experience?
  • they had 4 years experience?

Also, there is a typo in your label for players with 1 to 3 years experience.

If you were to correct your function to handle these situations and correct the typo, your answer will be accepted by the system.

Hello mathmike314
I tried adjusting my function, it worked but the results I get from bar plot is different from the one in DataQuest.
Again, I tried plotting the bar plot without the function as you suggested but did not work at all. I would like to know how I can plot without creating the function? Any more suggestion is welcome…Thanks again

Hi @wolewani My apologies for not seeing this sooner. Did you manage to figure this out on your own? I just finished doing this mission and have a much better understanding of the data if you still need some help with it.