Pandas Series: combine_first() function
Combine Series values in Pandas
The combine_first() function is used to combine Series values, choosing the calling Series’s values first.
Syntax:
Series.combine_first(self, other)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
other | The value(s) to be combined with the Series. | Series | Required |
Returns: Series
The result of combining the Series with the other object
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
s1 = pd.Series([2, np.nan])
s2 = pd.Series([4, 5])
s1.combine_first(s2)
Output:
0 2.0 1 5.0 dtype: float64
Previous: Combine the Series with a Series in Pandas
Next: Round each value in Pandas Series
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/pandas/series/series-combine_first.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics