看起来df.drop()
没有按预期工作(注意索引是DatetimeIndex):
>>> df
price bidvol askvol
datetime
2014-07-16 14:23:46.653000 34911 0 1
2014-07-16 14:23:53.705000 34909 5 0
2014-07-16 14:23:55.326000 34909 2 0
2014-07-16 14:23:59.539000 34908 1 0
2014-07-16 14:23:59.539000 34908 9 0
2014-07-16 14:24:00.219000 34908 2 0
>>> df = df.drop(df.ix['2014-07-16 14:24':])
>>> df
price bidvol askvol
datetime
2014-07-16 14:23:46.653000 34911 0 1
2014-07-16 14:23:53.705000 34909 5 0
2014-07-16 14:23:55.326000 34909 2 0
2014-07-16 14:23:59.539000 34908 1 0
2014-07-16 14:23:59.539000 34908 9 0
2014-07-16 14:24:00.219000 34908 2 0
我错过了什么吗?
答案 0 :(得分:0)
date = '2014-07-16 14:24'
删除范围:
df = df[:date] # Drops anything after the date
df = df[date:] # Drops anything before the date
要删除一行:
df = df.drop(Timestamp(date)) # Drops the row indexed by the date
这并不是因为日期不起作用。相反,它似乎不会像切片索引一样自动将字符串转换为日期。
检查docs。