0

so I'm having problems converting an object to an int in python. my code is

df['non_renewable'].astype(str).astype(int)

however, when I do this, I get the error code

ValueError: invalid literal for int() with base 10: '100%'

what are some solutions to this error?

JNevill
  • 46,980
  • 4
  • 38
  • 63
  • 1
    Does this answer your question? [Convert percent string to float in pandas read\_csv](https://stackoverflow.com/questions/25669588/convert-percent-string-to-float-in-pandas-read-csv) Essentially just do something like `df['non_renewable'].str.rstrip('%').astype(int)` – JNevill Feb 24 '22 at 16:11
  • `100%` isn't a number. You can't just cast it to an integer. What do you expect as a result? 1? 100? – Panagiotis Kanavos Feb 24 '22 at 16:11

0 Answers0