I have a columns which include stay_in_current_city_years. And there are some data like 4+

And i want to some algorithms. Firstly linear regression

from sklearn.linear_model import LinearRegression

ValueError: could not convert string to float: '4+'

1 Answers

JDunken On

If you are trying to remove the + then the easiest to understand way to remove it would be:

str = '4+'
str = str.replace('+', '') # this will replace the '+' with ''
str = str.strip() # this will remove the leading and trailing spaces, just in case, good practice, but might not be required, voila you have just the number