python对文件每行数据计算_如何在python中对pandas数据帧的每一行进行计算?

我是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本质上提供了代码,可以轻松地为此类问题共享数据子集。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值