當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pyspark Index.equals用法及代碼示例

本文簡要介紹 pyspark.pandas.Index.equals 的用法。

用法:

Index.equals(other: pyspark.pandas.indexes.base.Index) → bool

確定兩個 Index 對象是否包含相同的元素。

返回

bool

如果“other” 是一個索引並且它與調用索引具有相同的元素,則為真;否則為假。

例子

>>> from pyspark.pandas.config import option_context
>>> idx = ps.Index(['a', 'b', 'c'])
>>> idx.name = "name"
>>> midx = ps.MultiIndex.from_tuples([('a', 'x'), ('b', 'y'), ('c', 'z')])
>>> midx.names = ("nameA", "nameB")

對於索引

>>> idx.equals(idx)
True
>>> with option_context('compute.ops_on_diff_frames', True):
...     idx.equals(ps.Index(['a', 'b', 'c']))
True
>>> with option_context('compute.ops_on_diff_frames', True):
...     idx.equals(ps.Index(['b', 'b', 'a']))
False
>>> idx.equals(midx)
False

對於MultiIndex

>>> midx.equals(midx)
True
>>> with option_context('compute.ops_on_diff_frames', True):
...     midx.equals(ps.MultiIndex.from_tuples([('a', 'x'), ('b', 'y'), ('c', 'z')]))
True
>>> with option_context('compute.ops_on_diff_frames', True):
...     midx.equals(ps.MultiIndex.from_tuples([('c', 'z'), ('b', 'y'), ('a', 'x')]))
False
>>> midx.equals(idx)
False

相關用法


注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.pandas.Index.equals。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。