Python Forum
fixing error TypeError: 'float' object is not subscriptable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
fixing error TypeError: 'float' object is not subscriptable
#1
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!
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help fixing Index Error adesimone 1 2,303 Nov-21-2022, 07:03 PM
Last Post: deanhystad
  ERROR NoneType object has no attribute content denizkb 1 3,253 Nov-21-2019, 01:18 PM
Last Post: denizkb
  Error could not convert string to float: deadendstreet 4 6,937 Oct-02-2019, 05:49 PM
Last Post: ichabod801
  Fixing my backup function Beginner_coder123 4 3,969 Jun-15-2019, 07:56 PM
Last Post: Beginner_coder123
  getting an error"Line 7: TypeError: 'int' object is not callable" JTNA 4 8,294 Apr-03-2019, 01:58 PM
Last Post: JTNA
  Fixing arrays output in Python WLST script pkbash 2 5,105 Feb-28-2019, 06:20 PM
Last Post: pkbash
  Need help with fixing iteration counter Kapolt 8 6,116 Oct-18-2018, 07:56 PM
Last Post: buran
  i need help in fixing my scientific calculator coding : (, im using python 3.5.5 hans77 1 4,992 Oct-17-2018, 03:26 AM
Last Post: stullis
  Integer object error Zatoichi 2 4,578 Feb-18-2018, 07:25 AM
Last Post: Zatoichi
  text = str(text.encode('utf-8')) AttributeError: 'float' object has no attribute 'enc ulrich48155 2 10,122 Jul-31-2017, 05:21 PM
Last Post: ulrich48155

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020