用法:
Series.combine(other, func, fill_value=None)
根據
func
將係列與係列或標量組合。使用
func
組合係列和other
以對組合係列執行元素選擇。fill_value
假設在組合的兩個對象之一的某個索引處缺少值。- other:係列或標量
要與
Series
組合的值。- func:函數
將兩個標量作為輸入並返回一個元素的函數。
- fill_value:標量,可選
當一個係列或另一個係列中缺少索引時假定的值。默認指定為 Series 的基礎 dtype 使用適當的 NaN 值。
- Series
將 Series 與其他對象組合的結果。
參數:
返回:
例子:
考慮 2 個數據集
s1
和s2
,其中包含不同鳥類的最高時鍾速度。>>> s1 = pd.Series({'falcon':330.0, 'eagle':160.0}) >>> s1 falcon 330.0 eagle 160.0 dtype:float64 >>> s2 = pd.Series({'falcon':345.0, 'eagle':200.0, 'duck':30.0}) >>> s2 falcon 345.0 eagle 200.0 duck 30.0 dtype:float64
現在,結合這兩個數據集並查看兩個數據集中鳥類的最高速度
>>> s1.combine(s2, max) duck NaN eagle 200.0 falcon 345.0 dtype:float64
在前麵的示例中,鴨子的結果值丟失了,因為 NaN 和浮點數的最大值是 NaN。因此,在示例中,我們設置了
fill_value=0
,因此返回的最大值將是某個數據集的值。>>> s1.combine(s2, max, fill_value=0) duck 30.0 eagle 200.0 falcon 345.0 dtype:float64
相關用法
- Python pandas.Series.combine_first用法及代碼示例
- Python pandas.Series.compare用法及代碼示例
- Python pandas.Series.convert_dtypes用法及代碼示例
- Python pandas.Series.copy用法及代碼示例
- Python pandas.Series.cov用法及代碼示例
- Python pandas.Series.count用法及代碼示例
- Python pandas.Series.corr用法及代碼示例
- Python pandas.Series.cat.remove_categories用法及代碼示例
- Python pandas.Series.cat用法及代碼示例
- Python pandas.Series.cat.rename_categories用法及代碼示例
- Python pandas.Series.cumsum用法及代碼示例
- Python pandas.Series.cat.add_categories用法及代碼示例
- Python pandas.Series.cumprod用法及代碼示例
- Python pandas.Series.cummin用法及代碼示例
- Python pandas.Series.cummax用法及代碼示例
- Python pandas.Series.clip用法及代碼示例
- Python pandas.Series.cat.remove_unused_categories用法及代碼示例
- Python pandas.Series.add_prefix用法及代碼示例
- Python pandas.Series.map用法及代碼示例
- Python pandas.Series.max用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.combine。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。