@@ -8721,10 +8721,10 @@ def combine_first(
8721
8721
Combine two DataFrame objects by filling null values in one DataFrame
8722
8722
with non-null values from other DataFrame. The row and column indexes
8723
8723
of the resulting DataFrame will be the union of the two. The resulting
8724
- dataframe contains the 'first' dataframe values and overrides the
8725
- second one values where both first.loc[index, col] and
8726
- second.loc[index, col] are not missing values, upon calling
8727
- first.combine_first(second).
8724
+ DataFrame contains the 'first' DataFrame values and overrides the
8725
+ second one values where both ` first.loc[index, col]` and
8726
+ ` second.loc[index, col]` are not missing values, upon calling
8727
+ ` first.combine_first(second)` .
8728
8728
8729
8729
Parameters
8730
8730
----------
@@ -8734,7 +8734,6 @@ def combine_first(
8734
8734
Whether to sort the columns in the result DataFrame. If False, the
8735
8735
order of the columns in `self` is preserved.
8736
8736
8737
-
8738
8737
Returns
8739
8738
-------
8740
8739
DataFrame
@@ -8752,27 +8751,26 @@ def combine_first(
8752
8751
>>> df1 = pd.DataFrame({"A": [None, 0], "B": [None, 4]})
8753
8752
>>> df2 = pd.DataFrame({"A": [1, 1], "B": [3, 3]})
8754
8753
>>> df1.combine_first(df2)
8755
- A B
8754
+ A B
8756
8755
0 1.0 3.0
8757
8756
1 0.0 4.0
8758
8757
8759
-
8760
8758
Preserving the column order of `self` with `sort_columns=False`:
8761
8759
8762
8760
>>> df1 = pd.DataFrame({"B": [None, 4], "A": [0, None]})
8763
8761
>>> df2 = pd.DataFrame({"A": [1, 1], "B": [3, 3]})
8764
8762
>>> df1.combine_first(df2, sort_columns=False)
8765
- B A
8763
+ B A
8766
8764
0 3.0 0.0
8767
8765
1 4.0 1.0
8768
8766
8769
8767
Null values still persist if the location of that null value
8770
- does not exist in `other`
8768
+ does not exist in `other`.
8771
8769
8772
8770
>>> df1 = pd.DataFrame({"A": [None, 0], "B": [4, None]})
8773
8771
>>> df2 = pd.DataFrame({"B": [3, 3], "C": [1, 1]}, index=[1, 2])
8774
8772
>>> df1.combine_first(df2)
8775
- A B C
8773
+ A B C
8776
8774
0 NaN 4.0 NaN
8777
8775
1 0.0 3.0 1.0
8778
8776
2 NaN 3.0 1.0
0 commit comments