简体   繁体   English

看起来df.drop()在日期时间索引中不起作用

[英]looks like df.drop() doesn't the job for a datetime index

It looks like df.drop() is not working as expected (Note the index is a DatetimeIndex): 看起来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

Am I missing something? 我想念什么吗?

date = '2014-07-16 14:24'

To drop a range: 降低范围:

df = df[:date] # Drops anything after the date
df = df[date:] # Drops anything before the date

To drop a row: 删除行:

df = df.drop(Timestamp(date)) # Drops the row indexed by the date

It is not that drop doesn't work for dates. 并不是说下降不适用于日期。 It seems instead that it does not automatically converts strings to dates as slice indexing does. 相反,它似乎不会像切片索引那样自动将字符串转换为日期。

Check the docs . 检查文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM