我试图使用规范化= 30 * (x-min(x))/(max(x)-min(x))到0-30标度来规范这个变量。
在python中,应该是:
new_escore = esg_funds['Portfolio Environmental Score'].apply(lambda x: 30*(x-esg_funds['Portfolio Environmental Score'].min())/(esg_funds['Portfolio Environmental Score'].max()-esg_funds['Portfolio Environmental Score'].min()))esg_funds是我的数据,'Portfolio Environmental Score'是变量。
如何在这里使用apply()函数?
发布于 2022-11-07 18:19:12
由于R的矢量化操作,没有必要使用*apply()。相反,你可以:
new_escore <- 30 * (
esg_funds[['Portfolio Environmental Score']] - min(esg_funds[['Portfolio Environmental Score']])
) / (
max(esg_funds[['Portfolio Environmental Score']] - min(esg_funds[['Portfolio Environmental Score']]))
)或者更简洁一些,
normalize <- function(x) 30 * (x - min(x)) / (max(x) - min(x))
new_escore <- normalize(esg_funds[['Portfolio Environmental Score']])https://stackoverflow.com/questions/74350655
复制相似问题