pandas.Index.difference#
- final Index.difference(other, sort=None)[源代码]#
返回索引元素不在中的新索引 other 。
这是两个Index对象的设置差异。
- 参数
- other索引或类似数组
- sortFalse或None,默认为None
是否对结果索引进行排序。默认情况下,会尝试对这些值进行排序,但不可比元素中的任何TypeError都会被PANDA捕获。
无:尝试对结果进行排序,但通过比较不可比较的元素来捕获任何类型错误。
False:不对结果进行排序。
- 退货
- difference索引
示例
>>> idx1 = pd.Index([2, 1, 3, 4]) >>> idx2 = pd.Index([3, 4, 5, 6]) >>> idx1.difference(idx2) Int64Index([1, 2], dtype='int64') >>> idx1.difference(idx2, sort=False) Int64Index([2, 1], dtype='int64')