简体   繁体   English

使用Python脚本将'String Feature'数据框架转换为Azure ML中的Float

[英]Convert `String Feature` DataFrame into Float in Azure ML Using Python Script

I am trying to understand how to convert azure ml String Feature data type into float using python script. 我试图了解如何使用python脚本将azure ml String Feature数据类型转换为float。 my data set is contain "HH:MM" data time format. 我的数据集包含“ HH:MM”数据时间格式。 It recognized as String Feature like the following img: 它像下面的img一样被识别为String Feature

在此处输入图片说明

在此处输入图片说明

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. 我想将其转换为float类型,它将时间戳除以84600(24小时),因此17:30将被转换为0,729166666666667 ,所以我编写了python脚本来进行转换。 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 . 然后,我尝试检查它是否为str ,但返回None

can we treat String Feature as String ? 我们可以将String Feature视为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. to_numeric转换似乎是问题所在,因为没有从字符串到数字的默认解析。

Does it work if you just use pd.apply(timeToFloat) ? 如果仅使用pd.apply(timeToFloat)是否可以正常工作?

Roope - Microsoft Azure ML Team Roope-Microsoft Azure ML团队

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM