Code working on DQ but not on Jupyter

Hi everyone!

I’m currently on Transforming Data With Pandas (7. Reshaping Data with the Melt Function). The answer code worked on the website but not on my Jupyter*. It throws this error: TypeError: cannot convert the series to <type 'float'>

My machine has Python 2.7 so I thought that would be the case but I don’t see similar experiences in Stackoverflow. Would you know why it’s throwing a type error?

Sending the screenshots for your reference. Please let me know.


  • I do the exercises there so I can do more manipulation. The exercises tell me it’s wrong when I do other stuff from the instructions.

I found a workaround but still curious why the original code didn’t work on Jupyter

round function takes in a scalar (float) as a input. However, you are passing in a series. A series is not a float type. Hence the error occurs.

You can use assign the values first without the round method.

The use .apply to the new column to round.

df[percentage] = df[percentage].apply(lambda x: round(x, 2))