Pandas Index.difference(~) 方法返回一个新的 Index,其中包含索引中其他提供的索引中不存在的元素。
参数
1.other | Index 或 array-like
用于比较元素的另一个索引。
2. sort | False 或 None | optional
确定是否对返回的新Index进行排序。默认为 None 。
| 
 解释  | |
|---|---|
| 
 
  | 
 尝试对新的   | 
| 
 
  | 
 不要对新的   | 
返回值
新的 Index 包含索引中未包含在 other 中的元素。
例子
基本用法
要返回包含索引 a 和 b 之间差异的新索引:
import pandas as pd
a = pd.Index(["d","b","c", "a"])
b = pd.Index(["b","c"])
a.difference(b)
Index(['a', 'd'], dtype='object')
请注意新索引默认如何排序 sort=None 。
种类
要返回索引 a 和 b 之间的差异,而不对返回的结果索引进行排序:
import pandas as pd
a = pd.Index(["d","b","c", "a"])
b = pd.Index(["b","c"])
a.difference(b, sort=False)
Index(['d', 'a'], dtype='object')
请注意新索引如何未排序,并且 'd' 和 'a' 在索引 a 中按其原始顺序返回。
相关用法
- Python Pandas Index get_loc方法用法及代码示例
 - Python Django Index.expressions用法及代码示例
 - Python Django Index.include用法及代码示例
 - Python Int转Bytes用法及代码示例
 - Python Django InlineModelAdmin.get_extra用法及代码示例
 - Python Django InlineModelAdmin.raw_id_fields用法及代码示例
 - Python Pandas IntervalIndex构造函数用法及代码示例
 - Python InteractiveConsole runcode()用法及代码示例
 - Python InteractiveInterpreter runsource()用法及代码示例
 - Python InteractiveInterpreter runcode()用法及代码示例
 - Python IncrementalEncoder encode()用法及代码示例
 - Python Django InlineModelAdmin.get_max_num用法及代码示例
 - Python PIL Image.draft()用法及代码示例
 - Python PIL Image.thumbnail()用法及代码示例
 - Python PIL Image.new()用法及代码示例
 - Python PIL ImageOps.fit()用法及代码示例
 - Python Wand Image()用法及代码示例
 - Python PIL ImageDraw.Draw.rectangle()用法及代码示例
 - Python PIL ImageEnhance.Color() and ImageEnhance.Contrast()用法及代码示例
 - Python Itertools.zip_longest()用法及代码示例
 - Python PIL Image.getdata()用法及代码示例
 - Python Itertools.compress()用法及代码示例
 - Python PIL ImageFont.truetype()用法及代码示例
 - Python Itertools.count()用法及代码示例
 - Python PIL ImagePath.Path.tolist()用法及代码示例
 
注:本文由纯净天空筛选整理自Arthur Yanagisawa大神的英文原创作品 Pandas Index | difference method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
