I am trying to understand how to convert azure ml String Feature
data type into float using python script. my data set is contain "HH:MM" data time format. It recognized as String Feature
like the following img:
I want to convert it into float type which will divide the timestamp by 84600 ( 24 hour) so 17:30
will be converted into 0,729166666666667
, so I write python script to convert that. This is my script:
import pandas as pd
import numpy as np
def timeToFloat(x):
frt = [3600,60]
data = str(x)
result = float(sum([a*b for a,b in zip(frt, map(int,data.split(':')))]))/86400
return result if isNotZero(x) else 0.0
def isNotZero(x):
return (x is "0")
def azureml_main(dataframe1 = None):
df = pd.DataFrame(dataframe1)
df["Departure Time"] = pd.to_numeric(df["Departure Time"]).apply(timeToFloat)
print(df["Departure Time"])
return df,
When I run the script it was failed. Then I try to check whether it is str
or not, but it returns None
.
can we treat String Feature
as String
? or how should I covert this data correctly?
The to_numeric conversion seems to be the problem, as there's no default parsing from string to number.
Does it work if you just use pd.apply(timeToFloat) ?
Roope - Microsoft Azure ML Team
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.