Skip to content
Advertisement

Remove data time older than specific hours

I want to remove data from my dataframe older than say 2 hours from current time starting with 00 mins (datetime column is in index)

when i use below code

JavaScript
JavaScript

Current datetime: ’17-03-2022 17:05:00′

Issue: My code keeps all records in df from ’17-03-2022 15:05:00′ to ’17-03-2022 17:05:00′

Requirement: All records in df from ’17-03-2022 15:00:00′ to ’17-03-2022 17:05:00′

It should start from 00th minute of -2hrs

JavaScript

Advertisement

Answer

Use Timestamp.floor with change > to >=:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement