Skip to content
Advertisement

Remove ‘seconds’ and ‘minutes’ from a Pandas dataframe column

Given a dataframe like:

JavaScript

I would like to remove the ‘minutes’ and ‘seconds’ information.

The following (mostly stolen from: How to remove the ‘seconds’ of Pandas dataframe index?) works okay,

JavaScript

but it feels strange to convert a datetime to a string then back to a datetime. Is there a way to do this more directly?

Advertisement

Answer

dt.round

This is how it should be done… use dt.round

JavaScript

OLD ANSWER

One approach is to set the index and use resample

JavaScript

Another alternative is to strip the date and hour components

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