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
r=LinearRegression()
r.fit(x_train,y_train)
y_pred=r.predict(x_test)
print(y_pred)

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

1 Answers

-2
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