我试图从一个时间值从上午6点到下午8点的时间框架中删除每年两天的日期,日期从15.07到20.10。因此,我创建了一个列表,其中包含所有应该删除的日期,如下所示:
drop_list =[]
for i in range(0,6):
Year = 1999 + i
drop_list.append(str(Year)+'-07-15')
drop_list.append(str(Year)+'-07-16')
字符串
我的数据看起来像这样:
x1c 0d1x的数据
当我现在打电话:
y = y.drop(drop_list)
型
我得到:
KeyError:“2000 -07-15”“2000-07- 15”“2000 - 07 - 16 "" 2001-07 - 15”\n“2001 - 07 - 16 "”2002-07-15"“2002 - 07 - 16 "”2003 - 07 - 15“”2003 - 07 - 16“\n”2004-07- 15“”2004-07- 16 ']未在轴中找到”
任何建议我错过了什么?
1条答案
按热度按时间htrmnn0y1#
如果要从日期时间索引中删除,则需要传递日期时间。
例如
字符串
在您的情况下,
y.drop(pd.to_datetime(drop_list))
可能会工作。