Skip to content

Commit 62eb71c

Browse files
committed
DOC: document combine first, GH #161
1 parent e9dec0d commit 62eb71c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

doc/source/basics.rst

+23
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,29 @@ replace NaN with some other value using ``fillna`` if you wish).
157157
df + df2
158158
df.add(df2, fill_value=0)
159159
160+
Combining overlapping data sets
161+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
162+
163+
A problem occasionally arising is the combination of two similar data sets
164+
where values in one are preferred over the other. An example would be two data
165+
series representing a particular economic indicator where one is considered to
166+
be of "higher quality". However, the lower quality series might extend further
167+
back in history or have more complete data coverage. As such, we would like to
168+
combine two DataFrame objects where missing values in one DataFrame are
169+
conditionally filled with like-labeled values from the other DataFrame. The
170+
function implementing this operation is ``combine_first``, which we illustrate:
171+
172+
.. ipython:: python
173+
174+
df1 = DataFrame({'A' : [1., np.nan, 3., 5., np.nan],
175+
'B' : [np.nan, 2., 3., np.nan, 6.]})
176+
df2 = DataFrame({'A' : [5., 2., 4., np.nan, 3., 7.],
177+
'B' : [np.nan, np.nan, 3., 4., 6., 8.]})
178+
df1
179+
df2
180+
df1.combine_first(df2)
181+
182+
160183
.. _basics.stats:
161184

162185
Descriptive statistics

0 commit comments

Comments
 (0)