w3resource

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)
Pandas Series: combine_first() function

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



Become a Patron!

Follow us on Facebook and Twitter for latest update.

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