首页 > 解决方案 > 删除多个时间间隔

问题描述

我正在尝试从数据集中删除多个时间间隔。我有时间间隔的单独数据,并且我有我正在尝试清理的数据集。

drop_time.head()
Out[14]: 
                Start                 End
0 2019-01-28 19:50:00 2019-01-28 23:00:00
1 2019-03-12 00:40:00 2019-03-12 12:40:00
2 2019-03-12 16:20:00 2019-03-12 18:40:00
3 2019-04-12 15:30:00 2019-04-12 17:40:00
4 2019-05-12 07:40:00 2019-05-12 13:40:00
#Drop Dates
drop_time = pd.read_excel('Time_line.xlsx')

drop_start = drop_time['Start']
drop_end = drop_time['End']

index = 0
while index <= len(drop_start)-1:
    df_droped = df_clean.drop[(df_clean['Time'] > pd.Timestamp(drop_start.loc[index][0])) & 
                      (df_clean['Time'] < pd.Timestamp(drop_end.loc[index][0]))]

当我执行它时,我收到以下错误:

Traceback (most recent call last):

  File "<ipython-input-15-49cc734f7209>", line 8, in <module>
    df_droped = df_clean.drop[(df_clean['Time'] > pd.Timestamp(drop_start.loc[index][0])) &

TypeError: 'Timestamp' object is not subscriptable

标签: pythonpandastime-seriesdata-cleaning

解决方案


问题可能来自 pd.Timestamp(drop_start.loc[index][0])) 您的这部分代码(很难说)。但是有了这个,你是想获取一个元素还是它的索引?


推荐阅读