用法:
Series.compare(other, align_axis=1, keep_shape=False, keep_equal=False)
與另一個係列進行比較並顯示差異。
- other:Series
要比較的對象。
- align_axis:{0 或 ‘index’,1 或 ‘columns’},默認 1
確定要在哪個軸上對齊比較。
- 0,或‘index’產生的差異垂直堆疊
從 self 和 other 交替繪製的行。
- 1,或‘columns’產生的差異水平對齊
從 self 和 other 交替繪製列。
- keep_shape:布爾值,默認為 False
如果為真,則保留所有行和列。否則,僅保留具有不同值的那些。
- keep_equal:布爾值,默認為 False
如果為真,則結果保持相等的值。否則,相等的值顯示為 NaN。
- Series或DataFrame
如果軸為 0 或 ‘index’,則結果將是一個係列。生成的索引將是一個 MultiIndex,其中 ‘self’ and ‘other’ 在內部層交替堆疊。
如果軸為 1 或 ‘columns’,則結果將是一個 DataFrame。它將有兩列,即‘self’ and ‘other’。
參數:
返回:
注意:
匹配的 NaN 不會顯示為差異。
例子:
>>> s1 = pd.Series(["a", "b", "c", "d", "e"]) >>> s2 = pd.Series(["a", "a", "c", "b", "e"])
對齊列上的差異
>>> s1.compare(s2) self other 1 b a 3 d b
堆疊索引的差異
>>> s1.compare(s2, align_axis=0) 1 self b other a 3 self d other b dtype:object
保留所有原始行
>>> s1.compare(s2, keep_shape=True) self other 0 NaN NaN 1 b a 2 NaN NaN 3 d b 4 NaN NaN
保留所有原始行以及所有原始值
>>> s1.compare(s2, keep_shape=True, keep_equal=True) self other 0 a a 1 b a 2 c c 3 d b 4 e e
相關用法
- Python pandas.Series.combine_first用法及代碼示例
- Python pandas.Series.combine用法及代碼示例
- 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.compare。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。