熊猫:填充列中具有同一组的值
我需要填充列中的无空值,而不是同一组的零值。
我尝试使用变换与模式使用,但它没有完成工作。
test['col2']=test['col2'].transform(lambda x:x.fillna(x.mode())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 使用
模式
,如果存在,则选择第一个值,elsenone
,最后传递给Use
GroupBy.transform
withmode
and select first value if exist, elseNone
, last pass toSeries.fillna
:我将使用
.assign
和.apply
遍历每一行,然后找到模式:输出:
I would use
.assign
and.apply
to go through each row and then find the mode:output: