Answer is not accepted as correct

Hi,

I am on the Visualizing Frequency Distributions (9/13) where we have to generate a histogram for “Games Played” column of the wnba data set.

The solution which I have typed and the DQ solution is exactly the same (except for formatting) but my I get a error TypeError: 'str' object is not callable

Here’s my code:

wnba[‘Games Played’].plot.hist(range = (1,32), bins = 8, title = “The distribution of players by games played”)
plt.xlabel(“Games played”)

Here is DQ solution:

wnba['Games Played'].plot.hist(range = (1,32), bins = 8,
                               title = 'The distribution of players by games played')
plt.xlabel("Games played")

I get the error when I use plt.xlabel(“Games Played”) otherwise the code works fine. Am I missing something? Because the DQ code works fine and answer is accepted.

I have run both the codes 4-5 times. I get the same error with my code.

Here’s the full text of error:

TypeErrorTraceback (most recent call last)
in ()
4 wnba[‘Games Played’].plot.hist(range = (1,32), bins = 8,
5 title = ‘The distribution of players by games played’)
----> 6 plt.xlabel(“Games played”)

TypeError: ‘str’ object is not callable

Thank you!

When I ctrl+c ctrl+v the exact code you used, this is what I get:

The error message seems to be different from yours.

When I change the quotation marks (i.e. " and '), into characters the environment recognizes, your code seems to work after only making that one change. Notice how strings are distinguished with green text:

HI @blueberrypudding85,

Thanks for replying, but in my code editor, “The distribution of players by games played” was being recognized as a string. The quotes got changed when you copy-pasted it I think?

I ran the same code today and it was accepted! I think there was some issue yesterday with the code editor. Don’t know if I should mark this as solved or DQ should look into it…lol.

Adding the DQ Student Success Team @Sahil.

Hi @Sandesh,

First of all my sincere apologies for the late response. The issue you are experiencing is similar to what I explained in this post:

I assume that in one of your previous code run attempt, you assigned a string to plt.xlabel() function like this:


plt.xlabel = "Games played"

Since our platform remembers variable names until the container (code running environment) is destroyed or switched, the change you made to the function will persist on subsequent code runs. Here when you try to run the code again, it produces TypeError: 'str' object is not callable because the plt.xlabel's function definition got replaced by the string "Games played". And the error is just telling that we cannot call () a string (Example: "Hello World"()).

The reason that worked after sometime is because the container which got affected by this change was no longer in use.

The Fix
If you want to fix this issue immediately, you have to reload the library. And here is a post that explains how to do that.

Hope this helps :slightly_smiling_face:.

Best,
Sahil

1 Like

No worries Sahil, and thank you for replying!

1 Like