python - 删除多个时间间隔
问题描述
我正在尝试从数据集中删除多个时间间隔。我有时间间隔的单独数据,并且我有我正在尝试清理的数据集。
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
解决方案
问题可能来自
pd.Timestamp(drop_start.loc[index][0]))
您的这部分代码(很难说)。但是有了这个,你是想获取一个元素还是它的索引?
推荐阅读
- react-grid-layout - ReactGridLayout.children[0].y 必须是数字
- exception - 应该除以零引发异常
- asp.net-mvc - Asp Net Mvc Identity Multitenancy FindByEmailAsync 不工作
- spring - Spring 4 中的 ControllerAdvice 注释不起作用
- xamarin - Xamarin Forms - 如何让应用程序恢复到相同的视图 onResume
- arrays - BASH:在数组输出的一部分周围加双引号?
- c - 了解 UNIX fork() 如何影响父进程
- mongodb - 嵌套在数组中的数组的 MongoDB 投影
- python - Gurobi Python:代码是否满足约束?
- protractor - Angular 应用程序的量角器:E/启动器进程退出,错误代码为 199 - Chrome 挂断数据: