pandas 从另一个数据帧填充数据帧中的缺失值 [英] Pandas fill missing values in dataframe from another dataframe

查看:29
本文介绍了 pandas 从另一个数据帧填充数据帧中的缺失值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到一个 Pandas 函数(我以前见过)来用另一个数据帧中的值替换数据帧中的 NaN(假设可以指定一个公共索引).有什么帮助吗?

I cannot find a pandas function (which I had seen before) to substitute the NaN's in a dataframe with values from another dataframe (assuming a common index which can be specified). Any help?

推荐答案

如果你有两个形状相同的 DataFrame,那么:

If you have two DataFrames of the same shape, then:

df[df.isnull()] = d2

会解决问题.

只有 df.isnull() 计算结果为 True(以绿色突出显示)的位置才有资格进行赋值.

Only locations where df.isnull() evaluates to True (highlighted in green) will be eligible for assignment.

实际上,DataFrame 的大小/形状并不总是相同,转换方法(尤其是 .shift())很有用.

In practice, the DataFrames aren't always the same size / shape, and transforming methods (especially .shift()) are useful.

传入的数据总是脏的、不完整的或不一致的.课程标准.有一个非常广泛的 Pandas 教程和相关的食谱来处理这些情况.

Data coming in is invariably dirty, incomplete, or inconsistent. Par for the course. There's a pretty extensive pandas tutorial and associated cookbook for dealing with these situations.

这篇关于 pandas 从另一个数据帧填充数据帧中的缺失值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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