pandas 1.4.2

ParametersReturnsBackRef
combine_first(self, other: 'DataFrame') -> 'DataFrame'

Combine two DataFrame objects by filling null values in one DataFrame with non-null values from other DataFrame. The row and column indexes of the resulting DataFrame will be the union of the two.

Parameters

other : DataFrame

Provided DataFrame to use to fill null values.

Returns

DataFrame

The result of combining the provided DataFrame with the other object.

Update null elements with value in the same location in other .

See Also

DataFrame.combine

Perform series-wise operation on two DataFrames using a given function.

Examples

This example is valid syntax, but we were not able to check execution
>>> df1 = pd.DataFrame({'A': [None, 0], 'B': [None, 4]})
... df2 = pd.DataFrame({'A': [1, 1], 'B': [3, 3]})
... df1.combine_first(df2) A B 0 1.0 3.0 1 0.0 4.0

Null values still persist if the location of that null value does not exist in other

This example is valid syntax, but we were not able to check execution
>>> df1 = pd.DataFrame({'A': [None, 0], 'B': [4, None]})
... df2 = pd.DataFrame({'B': [3, 3], 'C': [1, 1]}, index=[1, 2])
... df1.combine_first(df2) A B C 0 NaN 4.0 NaN 1 0.0 3.0 1.0 2 NaN 3.0 1.0
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.frame.DataFrame.combine

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#7370
type: <class 'function'>
Commit: