Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to remove seconds from a datetime object

Here is my code to remove the seconds that some values in my df[‘time’] column that have seconds (ie. 10:05:35).

df = df[pd.to_datetime(df['time'], errors='coerce').notna()]
df = df[pd.to_datetime(df['date'], errors='coerce').notna()]
# Remove the seconds by setting the floor to minutes 'T'
df['time'] = df['time'].df.floor('T')

After running the above code I get this error, can anyone help?

AttributeError: ‘Series’ object has no attribute ‘df’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I unfortunately can’t comment yet, otherwise I would’ve commented.

Looking at this SO question it seems you have made a typo and need df['time'] = df['time'].dt.floor('T') where the difference is the dt instead of the df in between the dots.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading