![]() Model. Let's try to use pandas dataframe and convert strings into numeric classes from sklearn import preprocessing def convert (data): number preprocessing.LabelEncoder () data 'columnname' number.fittransform (data 'columnname') datadata. ValueError: could not convert string to float: '1,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,1' 55 Closed sjwwdz opened this issue yesterday 1 comment sjwwdz closed this as completed 16 hours ago Sign up for free to join this conversation on GitHub. Share this answer Posted 2-Oct-20 22:32pm. This means that you cannot convert a value if: This means that you cannot convert a value if: 1. ValueError: could not convert string to float: stop talking to other peoples girlfriends It is fairly obvious that the above string cannot be converted to a float value. # state_changed_at,deadline,created_at,launched_at are date time fields.Ĭols_to_use = The float() method only allows you to convert strings that appear like floats. Test = test.apply(lambda k: time.ctime(k)) Train = train.apply(lambda k: time.ctime(k)) # state_changed_at,deadline,created_at,launched_at are date time fields Train = pd.read_csv("datasets/train2.csv") You are loading strings into the float constructor here, which unless are under specific conditions, raises an error: dataset i float (x) for x in dataset i Instead of using a list comprehension, perhaps it would be better to use a for loop so you can more easily handle this case: data for x in dataset i: try: value float (x. Now the problem is, when I'm selecting those date features to train my model, it gives me an error:Ĭould not convert string to float: 'Thu Apr 16 23:58:58 2015' import pandas as pdįrom sklearn.naive_bayes import BernoulliNBįrom sklearn.naive_bayes import MultinomialNBįrom sklearn.naive_bayes import GaussianNB The Valueerror: could not convert string to float will be raised if we try to convert an incorrect string to a float. I'm converting it into proper date format. ValueError: could not convert string to float print (float ('A')) 1 Traceback (most recent call last): File 'main. For example column state_changed_at has value in csv as 1449619185. ![]() I've certain fields which are not in proper date format, so I converted it into UNIX format. ![]() I'm trying to solve one machine learning problem using GaussianNB. ![]() I'm beginner in python so please bare with me. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |