我使用python的库rpy2将R包应用到pandas dataframe
我想将包中的记分卡中的函数应用于pandas datframe,但当我遇到错误时,我不知道为什么
这是我的代码:
# python
import pandas as pd
import numpy as np
import rpy2
from rpy2.robjects.packages import importr
from rpy2.robjects import pandas2ri
from rpy2.robjects.vectors import DataFrame
# R
base = importr('base')
score = importr("scorecard")
# Create pandas df
df = pd.DataFrame( np.random.randn(5,4), # 5 rows, 2 columns
columns = ["A","B","C","D"], # name of columns
index = ["Max", "Nathy", "Tom", "Joe", "Kathy"] )
df["C"] = [0,0,1,0,1] # "BGI"
pandas2ri.activate()
# Convert pandas to r
df_r = pandas2ri.py2ri(df)
df_r = base.as_data_frame(df_r)
print(type(df_r))
pandas2ri.deactivate()
bins = score.woebin(df_r,
y = "C",
x = base.c("A","B") )
我在las命令中得到以下错误
^{pr2}$
这里有一个带有
pyper
的选项-检查输出
^{pr2}$这也可以通过}对象来实现。创建了一个python脚本('pytmp.py公司')
R
使用reticulate
获取{-在
R
中调用它注意:我们没有设置种子,所以每次运行的值都会不同
相关问题 更多 >
编程相关推荐