Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.1K
Views
Tiempo redondo a la hora más cercana python

Estaba tratando de redondear el tiempo a la hora más cercana en python en un marco de datos.

Supongamos que si una marca de tiempo es 2017-11-18 0:16 debería aparecer como 2017-11-18 0:00 y 2017-11-18 1:56 debería redondearse como 2017-11-18 2:00

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Experimenté un poco con jpp pero terminé con una solución diferente ya que agregar una hora en la hora 23 colapsó la cosa.

 from datetime import datetime, timedelta now = datetime.now() def hour_rounder(t): # Rounds to nearest hour by adding a timedelta hour if minute >= 30 return (t.replace(second=0, microsecond=0, minute=0, hour=t.hour) +timedelta(hours=t.minute//30)) print(now) print(hour_rounder(now))

Devoluciones:

 2018-02-22 23:42:43.352133 2018-02-23 00:00:00
over 4 years ago · Santiago Trujillo Report

0

import pandas as pd pd.Timestamp.now().round('60min').to_pydatetime()

Devoluciones:

 datetime.datetime(2018, 2, 23, 0, 0)
over 4 years ago · Santiago Trujillo Report

0

Esta es una forma.

 from datetime import datetime now = datetime.now() def rounder(t): if t.minute >= 30: return t.replace(second=0, microsecond=0, minute=0, hour=t.hour+1) else: return t.replace(second=0, microsecond=0, minute=0) now # 2018-02-22 22:03:53.831589 rounder(now) # 2018-02-22 22:00:00.000000
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!