1

The code is returning the wrong hour at 09/04/2023 11:00:00. It is returning me the hour 10 for some reason.

I have a date column in a excel sheet with every hour in 2023 (01/01/2023 01:00:00 till today) and I used these lines in my python code:

colunas_planilha2['Hora'] = pd.to_datetime(colunas_planilha2['Dia/Hora'])
colunas_planilha2['Hora dt'] = pd.to_datetime(colunas_planilha2['Dia/Hora']).dt.hour

But I notice something wrong at 09/04/2023 11:00:00: https://i.stack.imgur.com/iwAk2.png

for some reason it's returning me the hour 10

Why did it happen? How can I fix it?

  • Try changing the column names to ones not containing / – gtomer Jul 31 '23 at 17:28
  • 3
    @gtomer Why would the column name matter? – Barmar Jul 31 '23 at 17:30
  • 4
    I suspect this is a timezone issue, or maybe Daylight Saving Time. – Barmar Jul 31 '23 at 17:30
  • Welcome to Stack Overflow! Please post code, data, and results as text, not screenshots ([how to format code in posts](https://stackoverflow.com/help/formatting)). [Why should I not upload images of code/data/errors?](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors) http://idownvotedbecau.se/imageofcode – Barmar Jul 31 '23 at 17:31
  • @Barmar - special char. in column name sometime do weird things – gtomer Jul 31 '23 at 17:33
  • @gtomer I find that very difficult to believe. Can you provide an example or reference? – Barmar Jul 31 '23 at 17:34
  • You can control `import time print(time.strftime("Date and Time Zone: %Y-%m-%d %H:%M:%S %Z, The time offset: %z", time.localtime())) ` to see what time zone you are working. – Hermann12 Jul 31 '23 at 17:51
  • @Hermann12 it printed "Date and Time Zone: 2023-07-31 14:56:12 E. South America Standard Time, The time offset: -0300" im brazilian. if it is a timezone issue how can i fix that? – Rodrigo Araujo Mendes Jul 31 '23 at 17:58
  • @Barmar according to google, Brazil doesn't have daylight savings – Mark Aug 01 '23 at 02:14
  • @RodrigoAraujoMendes are you in Brazil? – Mark Aug 01 '23 at 02:15

0 Answers0