通过Revoscalepy在新表中创建新列

时间:2019-01-21 11:29:57

标签: python python-3.x revoscalepy

我正在处理一个数据集,在该数据集中我需要基于现有列创建一个新列,简而言之,我正在使用rx_data_step转换变量。

我正在关注以下Microsoft文档。

https://docs.microsoft.com/en-us/machine-learning-server/python-reference/revoscalepy/rx-data-step

在Microsoft文档中,我正在尝试通过.xdf文件创建新列,我想通过data_source对象实现相同的目的。

conn_str="Driver=SQL 
Server;Server=xxxx;Database=yyyyy;Trusted_Connection=True"

##Input data source object 

data_source = RxSqlServerData(sql_query = select * from
DummyTable,connection_string=conn_str)

Output Table
sqlOutScoreDS2 = RxSqlServerData(table = 
"NewTable",connection_string=conn_str)


# Function to label whether the age in month is over 120 months.
month_limit = 120

new_col_name = "Over10Yr"

def transformFunc(data, cutoff, new_col_name):
    ret = data
    ret[new_col_name] = data.apply(lambda row: True if row.Age > cutoff 
    else 
    False, axis=1)
    return ret

rx_data_step(input_data=data_source, transform_function=transformFunc,
                       transform_objects={"cutoff": month_limit, 
"new_col_name": new_col_name},output_file=sqlOutScoreDS2)

0 个答案:

没有答案