Skip to content
Advertisement

Deleting rows based on time interval in pandas

I have a dataframe with datetime timestamps (every 1 minute). I’d like to increase the time interval between rows to 5 minutes. Basically keep rows 0, 5, 10 etc and remove the rest. How would I do that?

JavaScript

Thanks

Advertisement

Answer

Firstly convert your date column to datetime dtype by using to_datetime() method(If its already of datetime then ignore this step):

JavaScript

Finally You can do this by boolean masking:

JavaScript

Now if you prints newdf you will get your desired output:

JavaScript

If needed use reset_index() method:

JavaScript

Output of above code:

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