【发布时间】:2018-07-19 19:04:19
【问题描述】:
我是 python 的新手,我正在尝试将我在 R 中创建的函数转换为 Python,此处描述的 R 函数:
从我的阅读看来,在 python 中执行此操作的最佳方法是使用采用以下形式的 for 循环
for line 1 in probe test
find user in U_lookup
find movie in M_lookup
take the value found in U_lookup and retrieve that line number from knn_text
take the values found in that row of knn_text, and retrieve the line numbers from dfm
for those line numbers in dfm, retrieve column=U_lookup
take the average of the non zero values found
save value into pandas datafame in new column for that line
这是完成此类操作的最有效(就计算速度而言)方法吗?来自 R,所以我不确定 pandas 包中是否有更好的功能。
作为后续,python 中是否有与 R 中的函数 dput() 等效的函数? dput 本质上提供了代码来轻松共享此类问题的数据子集。
【问题讨论】:
-
谷歌你的问题,google.com/…
-
循环几乎肯定不是最有效的方法。您可能想要
pandas.merge或只是一个简单的映射,但如果您想要一个详细的答案,您需要创建一个minimal reproducible example。