执行时:
import pandas
from datetime import datetime
timestampparse = lambda t: datetime.fromtimestamp(float(t))
df = pandas.read_csv('blah.csv', delimiter=';', parse_dates=True, date_parser=timestampparse, index_col='DateTime', names=['DateTime', 'Sell'], header=None)
print df.ix['2015-12-02 12:02:21.070':'2015-12-02 12:40:21.070']
用这个布拉赫.csv文件:
1449054136.83;1.05905
1449054139.25;1.05906
1449054139.86;1.05906
1449054140.47;1.05906
我得到这个错误:
KeyError
如何访问按日期筛选的数据帧片段?
为什么df.ix['2015-12-02 12:02:19.000':'2015-12-02 12:40:21.070']
不起作用?
从docs和Time/Date Components我知道您需要指定微秒的数量(与datetime对象相同):
或者使用
datetime
精确指定微秒数:用零填充第二个分数
'2015-12-02 12:02:16.0859'
:这样做有效:
这适用于版本0.16.2
我认为它不起作用,因为在
datetimeindex
和floatindex
中可能存在精度问题。你知道吗您可以使用partial string indexing,其中我省略了datetime结尾的数字-我只使用秒:
相关问题 更多 >
编程相关推荐