Why does .loc have inclusive behavior for slices?
问题 For some reason, the following 2 calls to iloc / loc produce different behavior: >>> import pandas as pd >>> df = pd.DataFrame(dict(A=range(3), B=range(3))) >>> df.iloc[:1] A B 0 0 0 >>> df.loc[:1] A B 0 0 0 1 1 1 I understand that loc considers the row labels, while iloc considers the integer-based indices of the rows. But why is the upper bound for the loc call considered inclusive, while the iloc bound is considered exclusive? 回答1: Quick answer: It often makes more sense to do end