Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.combine#

Series.combine(other,func,fill_value=None)[source]#

Combine the Series with a Series or scalar according tofunc.

Combine the Series andother usingfunc to perform elementwiseselection for combined Series.fill_value is assumed when value is missing at some indexfrom one of the two objects being combined.

Parameters:
otherSeries or scalar

The value(s) to be combined with theSeries.

funcfunction

Function that takes two scalars as inputs and returns an element.

fill_valuescalar, optional

The value to assume when an index is missing fromone Series or the other. The default specifies to use theappropriate NaN value for the underlying dtype of the Series.

Returns:
Series

The result of combining the Series with the other object.

See also

Series.combine_first

Combine Series values, choosing the calling Series’ values first.

Examples

Consider 2 Datasetss1 ands2 containinghighest clocked speeds of different birds.

>>>s1=pd.Series({'falcon':330.0,'eagle':160.0})>>>s1falcon    330.0eagle     160.0dtype: float64>>>s2=pd.Series({'falcon':345.0,'eagle':200.0,'duck':30.0})>>>s2falcon    345.0eagle     200.0duck       30.0dtype: float64

Now, to combine the two datasets and view the highest speedsof the birds across the two datasets

>>>s1.combine(s2,max)duck        NaNeagle     200.0falcon    345.0dtype: float64

In the previous example, the resulting value for duck is missing,because the maximum of a NaN and a float is a NaN.So, in the example, we setfill_value=0,so the maximum value returned will be the value from some dataset.

>>>s1.combine(s2,max,fill_value=0)duck       30.0eagle     200.0falcon    345.0dtype: float64

[8]ページ先頭

©2009-2025 Movatter.jp