@@ -157,6 +157,29 @@ replace NaN with some other value using ``fillna`` if you wish).
157
157
df + df2
158
158
df.add(df2, fill_value = 0 )
159
159
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
+
160
183
.. _basics.stats :
161
184
162
185
Descriptive statistics
0 commit comments