pandas.errors.UnsortedIndexError # 异常 pandas.errors。UnsortedIndexError [来源] # 对尚未进行词法排序的 MultiIndex 进行切片时引发错误。 KeyError的子类。 例子 >>> df = pd.DataFrame({"cat": [0, 0, 1, 1], ... "color": ["white", "white", "brown", "black"], ... "lives": [4, 4, 3, 7]}, ... ) >>> df = df.set_index(["cat", "color"]) >>> df lives cat color 0 white 4 white 4 1 brown 3 black 7 >>> df.loc[(0, "black"):(1, "white")] Traceback (most recent call last): UnsortedIndexError: 'Key length (2) was greater than MultiIndex lexsort depth (1)'