Pandas DataFrame combine_first() 方法
示例
合并两个 DataFrame,并在第一个 DataFrame 为 NULL 时使用第二个 DataFrame 的数据
import pandas as pd
df1 = pd.DataFrame([[1, 2], [None, 4]])
df2 = pd.DataFrame([[5, 6], [7, 8]])
print(df1.combine_first(df2))
自己动手试一试 »
定义和用法
combine_first()
方法合并两个 DataFrame 对象,并在第一个 DataFrame 中遇到 NULL 值时,使用第二个 DataFrame 中的值。
语法
dataframe.combine_first(other)
参数
参数 | 描述 |
---|---|
other | 必需。一个 DataFrame。 |
返回值
一个 DataFrame 对象。