urely integer-location based indexing for selection by position. .iloc[] is primarily integer position based (from 0 to length-1 of the axis), but may also be used with a boolean array. Allowed inputs are: An integer, e.g. 5. A list or array of integers, e.g. [4, 3, 0]. A slice object with ints, e.g. 1:7. A boolean array. A callable function with one argument (the calling Series or DataFrame) and that returns valid output for indexing (one of the above). This is useful in method chains, when you don't have a reference to the calling object, but would like to base your selection on some value. .iloc will raise IndexError if a requested indexer is out-of-bounds, except slice indexers which allow out-of-bounds indexing (this conforms with python/numpy slice semantics). See more at Selection by Position .
时间: 2024-04-19 08:30:11 浏览: 169
`.iloc[]` 是一种基于整数位置的索引方式,用于根据位置选择数据。
`.iloc[]` 主要是基于整数位置进行索引(从 0 到轴长度-1),但也可以与布尔数组一起使用。
允许的输入有:
- 一个整数,例如 5。
- 一个整数列表或数组,例如 [4, 3, 0]。
- 一个整数切片对象,例如 1:7。
- 一个布尔数组。
- 一个可调用函数,接受一个参数(调用的 Series 或 DataFrame),并返回有效的索引输出(上述任意一种)。这在方法链中非常有用,当你没有对调用对象的引用,但想要根据某个值进行选择时。
如果请求的索引超出了范围,`.iloc` 会引发 IndexError,但切片索引允许超出范围的索引(这符合 Python/NumPy 的切片语义)。
更多信息请参阅 Selection by Position。
阅读全文