【发布时间】:2019-06-21 05:36:56
【问题描述】:
我刚开始学习 Pandas,我不明白当索引列表包含多种类型的对象时切片是如何工作的。
import pandas as pd
arr = pd.Series([10, 20, 30, 40], index = [2, 3, 'six', 'eight'])
arr[2:3] #Output -- 30
arr[3:'six'] #TypeError: cannot do slice indexing on <class 'pandas.core.indexes.base.Index'> with these indexers [3] of <class 'int'>
arr['six':'eight'] #Output -- 30, 40
arr[2:3] 不应该是 20,arr['six':'eight'] 不应该是 30 吗?
【问题讨论】:
-
没关系,我找到了答案here。