如何解决此 OML4py 代理错误?

问题描述 投票:0回答:1

例如,apply 函数适用于 pandas DataFrame,但 OML 数据框不支持 apply 方法。我收到此错误

AttributeError:“DataFrame”对象没有属性“apply”

我该如何解决这个问题?

''' %蟒蛇

import oml
import pandas as pd

inp = [{'VAL_1':10, 'VAL_2':1}, {'VAL_1':11,'VAL_2':10}, {'VAL_1':12,'VAL_2':0}]
df = pd.DataFrame(inp)
oml_df = oml.push(df)

# The apply function works with the pandas DataFrame:

%python

df['VAL_NEW'] = df.apply(lambda row, arg: row['VAL_1'] + row['VAL_2'] +100, axis=1, args=(100,))
print(df)

# But OML dataframes don't support the apply method:

%python

oml_df['VAL_NEW'] = oml_df.apply(lambda row, arg: row['VAL_1'] + row['VAL_2'] +100, axis=1, args=(100,))

# AttributeError: 'DataFrame' object has no attribute 'apply'

'''

python machine-learning
1个回答
0
投票

OML4Py 不会重载 apply 方法。使用 + 和 concat 方法可以实现等效代码。

%python

new_col = oml_df['VAL_1'] + oml_df['VAL_2'] + 100
oml_df = oml_df.concat({"VAL_NEW": new_col})
oml_df

 VAL_1  VAL_2  VAL_NEW
0     12      0      112
1     10      1      111
2     11     10      121
© www.soinside.com 2019 - 2024. All rights reserved.