对 python 中的索引切片感到困惑
Confused on Index Slicing in python
我正在对我的小时列进行切片,当我使用 slice(1, 3) 和 slice(0, 3) 时,我得到了相同的结果。我错过了什么?请参见下图。
如果需要从时间中提取一个小时,最好使用:
dataset['hour'] = pd.to_datetime(dataset['hour'],format= '%H:%M:%S' ).dt.hour
dataset["hour"]
开头有个space。
所以 slice(0, 3)
是“02”,而 slice(1, 3)
是“02”。
@Barmar 在 上回答了这个问题。
我正在对我的小时列进行切片,当我使用 slice(1, 3) 和 slice(0, 3) 时,我得到了相同的结果。我错过了什么?请参见下图。
如果需要从时间中提取一个小时,最好使用:
dataset['hour'] = pd.to_datetime(dataset['hour'],format= '%H:%M:%S' ).dt.hour
dataset["hour"]
开头有个space。
所以 slice(0, 3)
是“02”,而 slice(1, 3)
是“02”。
@Barmar 在