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


Python cudf.Index.intersection用法及代碼示例

用法:

Index.intersection(other, sort=False)

形成兩個 Index 對象的交集。

這將返回一個新索引,其中包含索引和 other 共有的元素。

參數

other索引或array-like
sort假或無,默認假

是否對結果索引進行排序。

  • False:不對結果進行排序。
  • 無:對結果進行排序,除非 selfother 相等或無法比較值。

返回

intersection index

例子

>>> import cudf
>>> import pandas as pd
>>> idx1 = cudf.Index([1, 2, 3, 4])
>>> idx2 = cudf.Index([3, 4, 5, 6])
>>> idx1.intersection(idx2)
Int64Index([3, 4], dtype='int64')

多索引案例

>>> idx1 = cudf.MultiIndex.from_pandas(
...    pd.MultiIndex.from_arrays(
...         [[1, 1, 3, 4], ["Red", "Blue", "Red", "Blue"]]
...    )
... )
>>> idx2 = cudf.MultiIndex.from_pandas(
...    pd.MultiIndex.from_arrays(
...         [[1, 1, 2, 2], ["Red", "Blue", "Red", "Blue"]]
...    )
... )
>>> idx1
MultiIndex([(1,  'Red'),
            (1, 'Blue'),
            (3,  'Red'),
            (4, 'Blue')],
        )
>>> idx2
MultiIndex([(1,  'Red'),
            (1, 'Blue'),
            (2,  'Red'),
            (2, 'Blue')],
        )
>>> idx1.intersection(idx2)
MultiIndex([(1,  'Red'),
            (1, 'Blue')],
        )
>>> idx1.intersection(idx2, sort=False)
MultiIndex([(1,  'Red'),
            (1, 'Blue')],
        )

相關用法


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