在Fillna中使用自定义函数系列 [英] Using a custom function Series in fillna

查看:142
本文介绍了在Fillna中使用自定义函数系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在熊猫中添加自定义功能吗?

Can I have a custom function for fill na in Pandas?

s.fillna(lambda r:r ["SomeColumn"] ** 2)

s.fillna(lambda r: r["SomeColumn"]**2)

我很想拥有一个可以包含在整行中的自定义函数.

I'd love to have a custom function that could take in the entire row itself.

推荐答案

value参数可以是Series或DataFrame.因此,您可以提前计算正确的值,然后将其传递给.fillna

The value argument can be a Series or DataFrame. So you could calculate the correct value ahead of time, and pass that to .fillna

fill_value = s['SomeColumn'] ** 2
s.fillna(fill_value)

这篇关于在Fillna中使用自定义函数系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆