Issue
I followed this article to build an SVM model on my data. https://stackabuse.com/implementing-svm-and-kernel-svm-with-pythons-scikit-learn/
here a sample of my data: here
the problem is when I run the code this error appeared:
ValueError: could not convert string to float: '10/29/2020 8:30'
Solution
You can convert your date to timestamp and handle it accordingly.
import datetime
s = '10/29/2020 8:30'
date = datetime.datetime.strptime(s, "%m/%d/%Y %H:%M")
date = date.timestamp()
date
will now be 1603953000.0
.
Edit: if you want to covert pandas dataframe columns, here's a toy example.
import pandas as pd
s = '10/29/2020 8:30'
df = pd.DataFrame({'Date':[s, s, s]})
df['Date'] = pd.to_datetime(df['Date'])
df['Date'] = df['Date'].astype('int64')
output:
Date
0 1603960200000000000
1 1603960200000000000
2 1603960200000000000
Answered By - Alex Metsai
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.