maxframe.dataframe.Series.compare#

Series.compare(other, align_axis: int | str = 1, keep_shape: bool = False, keep_equal: bool = False, result_names: Tuple[str, str] = ('self', 'other'))#

与另一个 Series 比较并显示差异。

参数:
  • other (Series) -- 用于比较的对象。

  • align_axis ({0 or 'index', 1 or 'columns'}, default 1) -- 确定比较结果对齐的轴。 * 0 或 'index':结果差异垂直堆叠,行交替地从 self 和 other 中提取。* 1 或 'columns':结果差异水平对齐,列交替地从 self 和 other 中提取。

  • keep_shape (bool, default False) -- 如果为 True,则保留所有行和列。否则,只保留值不同的项。

  • keep_equal (bool, default False) -- 如果为 True,则结果保留相等的值。否则,相等的值显示为 NaN。

  • result_names (tuple, default (‘self’, ‘other’)) -- 在比较中设置 DataFrame 的名称。

返回:

如果 axis 为 0 或 'index',结果将是一个 Series。其索引将是一个 MultiIndex,'self' 和 'other' 在内层交替堆叠。如果 axis 为 1 或 'columns',结果将是一个 DataFrame,它将包含两个列,即 'self' 和 'other'。

返回类型:

Series or DataFrame

参见

DataFrame.compare

与另一个 DataFrame 比较并显示差异。

备注

匹配的 NaN 不会被视为差异。

示例

>>> import maxframe.dataframe as md
>>> s1 = md.Series(["a", "b", "c", "d", "e"])
>>> s2 = md.Series(["a", "a", "c", "b", "e"])

将差异按列对齐

>>> s1.compare(s2).execute()
  self other
1    b     a
3    d     b

将差异按索引堆叠

>>> s1.compare(s2, align_axis=0).execute()
1  self     b
   other    a
3  self     d
   other    b
dtype: object

保留所有原始行

>>> s1.compare(s2, keep_shape=True).execute()
  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).execute()
  self other
0    a     a
1    b     a
2    c     c
3    d     b
4    e     e