Combine the Series with a Series or scalar according to `func`. Combine the Series and `other` using `func` to perform elementwise selection for combined Series. `fill_value` is assumed when value is not present at some index from one of the two Series being
(
self,
other: Series | Hashable,
func: Callable[[Hashable, Hashable], Hashable],
fill_value: Hashable | None = None,
)
| 3262 | ) |
| 3263 | |
| 3264 | def combine( |
| 3265 | self, |
| 3266 | other: Series | Hashable, |
| 3267 | func: Callable[[Hashable, Hashable], Hashable], |
| 3268 | fill_value: Hashable | None = None, |
| 3269 | ) -> Series: |
| 3270 | """ |
| 3271 | Combine the Series with a Series or scalar according to `func`. |
| 3272 | |
| 3273 | Combine the Series and `other` using `func` to perform elementwise |
| 3274 | selection for combined Series. |
| 3275 | `fill_value` is assumed when value is not present at some index |
| 3276 | from one of the two Series being combined. |
| 3277 | |
| 3278 | Parameters |
| 3279 | ---------- |
| 3280 | other : Series or scalar |
| 3281 | The value(s) to be combined with the `Series`. |
| 3282 | func : function |
| 3283 | Function that takes two scalars as inputs and returns an element. |
| 3284 | fill_value : scalar, optional |
| 3285 | The value to assume when an index is missing from |
| 3286 | one Series or the other. The default specifies to use the |
| 3287 | appropriate NaN value for the underlying dtype of the Series. |
| 3288 | |
| 3289 | Returns |
| 3290 | ------- |
| 3291 | Series |
| 3292 | The result of combining the Series with the other object. |
| 3293 | |
| 3294 | See Also |
| 3295 | -------- |
| 3296 | Series.combine_first : Combine Series values, choosing the calling |
| 3297 | Series' values first. |
| 3298 | |
| 3299 | Examples |
| 3300 | -------- |
| 3301 | Consider 2 Datasets ``s1`` and ``s2`` containing |
| 3302 | highest clocked speeds of different birds. |
| 3303 | |
| 3304 | >>> s1 = pd.Series({"falcon": 330.0, "eagle": 160.0}) |
| 3305 | >>> s1 |
| 3306 | falcon 330.0 |
| 3307 | eagle 160.0 |
| 3308 | dtype: float64 |
| 3309 | >>> s2 = pd.Series({"falcon": 345.0, "eagle": 200.0, "duck": 30.0}) |
| 3310 | >>> s2 |
| 3311 | falcon 345.0 |
| 3312 | eagle 200.0 |
| 3313 | duck 30.0 |
| 3314 | dtype: float64 |
| 3315 | |
| 3316 | Now, to combine the two datasets and view the highest speeds |
| 3317 | of the birds across the two datasets |
| 3318 | |
| 3319 | >>> s1.combine(s2, max) |
| 3320 | duck NaN |
| 3321 | eagle 200.0 |