gpt4 book ai didi

python - Pandas 在时间序列上的切片似乎与列表切片不一致

转载 作者:行者123 更新时间:2023-11-30 23:42:40 26 4
gpt4 key购买 nike

times = [datetime(2011, 01, 03, 0, 10 + i, 0) for i in range(5)]
series = pd.TimeSeries(range(5), index=times)
series.ix[datetime(2011, 01, 03, 0, 10, 0):datetime(2011, 01, 03, 0, 13, 0)]

2011-01-03 00:10:00 0
2011-01-03 00:11:00 1
2011-01-03 00:12:00 2
2011-01-03 00:13:00 3

但是

x = range(5)
x[0:3]
[0, 1, 2]

另外,

times = [datetime.datetime(2000, 1, 1) + datetime.timedelta(minutes=i) for i in range(1000000 - 1)]
df = pd.TimeSeries(range(1000000 - 1), times)
len(df.ix[datetime.datetime(1900,1,1):datetime.datetime(2100,1,1)])

999999

但是

times = [datetime.datetime(2000, 1, 1) + datetime.timedelta(minutes=i) for i in range(1000000)]
df = pd.TimeSeries(range(1000000), times)
len(df.ix[datetime.datetime(1900,1,1):datetime.datetime(2100,1,1)])

回溯(最近一次调用最后一次):

  File "C:\Program Files (x86)\Wing IDE 4.1\src\debug\tserver\_sandbox.py", line 1, in <module>
# Used internally for debug sandbox under external interpreter
File "C:\dev\Python26\Lib\site-packages\pandas\core\indexing.py", line 35, in __getitem__
return self._getitem_axis(key, axis=0)
File "C:\dev\Python26\Lib\site-packages\pandas\core\indexing.py", line 234, in _getitem_axis
return self._get_slice_axis(key, axis=axis)
File "C:\dev\Python26\Lib\site-packages\pandas\core\indexing.py", line 460, in _get_slice_axis
i, j = labels.slice_locs(start, stop)
File "C:\dev\Python26\Lib\site-packages\pandas\tseries\index.py", line 949, in slice_locs
return Index.slice_locs(self, start, end)
File "C:\dev\Python26\Lib\site-packages\pandas\core\index.py", line 1057, in slice_locs
end_slice = self.get_loc(end) + 1
File "C:\dev\Python26\Lib\site-packages\pandas\tseries\index.py", line 919, in get_loc
return self._engine.get_loc(key)
File "C:\dev\Python26\Lib\site-packages\pandas\lib.pyd", line 378, in pandas.lib.DatetimeEngine.get_loc (pandas\src\tseries.c:108808)
File "C:\dev\Python26\Lib\site-packages\pandas\lib.pyd", line 390, in pandas.lib.DatetimeEngine.get_loc (pandas\src\tseries.c:108422)
File "C:\dev\Python26\Lib\site-packages\pandas\lib.pyd", line 32, in util.get_value_at (pandas\src\tseries.c:112091)
IndexError: index out of bounds

最佳答案

来自documentation :

带标签的切片在语义上略有不同,因为在基于标签的情况下,切片的开始和结束是包含

关于python - Pandas 在时间序列上的切片似乎与列表切片不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11306167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com