Python Forum
fixing error TypeError: 'float' object is not subscriptable - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: fixing error TypeError: 'float' object is not subscriptable (/thread-39303.html)



fixing error TypeError: 'float' object is not subscriptable - programmingirl - Jan-28-2023

Hi there. I am working on a project on loan defaults and I am trying to convert the term variable into 36 or 60 integer numeric data type using .apply() or .map().

This is my code
loans['term'] = loans['term'].apply(lambda term: int(term[:3]))

and it is returning the error that the float object is not subscriptable. How do I fix this so I can proceed?
Thank you!


RE: fixing error TypeError: 'float' object is not subscriptable - deanhystad - Jan-28-2023

You don't provide enough information. What is loans? Is it a dictionary? Is it a DataFrame? Is it something else? Please post the code where loans is created.

The messages says that loans is a float or that term is a float. Or the error could be for some other instruction and you only think it is for the instruction in your post. Along with posting more code, you should post the complete error message, including the traceback.