0

I got data that the time format include some rows that the time is more than 24 hours.

the data also incluse date parameter

time 26:00 mean the day after at 2:00

max time is 28:00

I want to create datetime parameter but because the time parameter is an object it doesn't let me to it. and when I try to convert it says "hour must be in 0..23: 24:00:02"

any suggestion what to do?

edit: i need the date time

enter image description here

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
rafine
  • 361
  • 3
  • 18
  • 1
    Please post a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – RJ Adriaansen Mar 03 '21 at 13:52
  • ...which should contain exemplary data as text, not image. also, are you using pandas? – FObersteiner Mar 03 '21 at 14:08
  • Does this answer your question? [Pandas: add timedelta column to datetime column (vectorized)](https://stackoverflow.com/questions/38355816/pandas-add-timedelta-column-to-datetime-column-vectorized) – FObersteiner Mar 03 '21 at 14:28

1 Answers1

1

You could use to_timedelta and to_datetime from pandas.

df['date time'] =  pd.to_datetime(df['date'], format='%d.%m.%y') + pd.to_timedelta(df['time'])
norie
  • 9,609
  • 2
  • 11
  • 18
  • for the format provided by the OP, it might be good to set `format='%d.%m.%y'` (or at least `dayfirst=True`, depending on what comes first). – FObersteiner Mar 03 '21 at 14:27
  • I've added the format argument - when I originally tested the code it worked fine without it, that's why I didn't include it in my original answer. – norie Mar 03 '21 at 14:37
  • sure, it works without, but pandas will use month-first by default - which is not what the OP has in his sample ;-) – FObersteiner Mar 03 '21 at 14:49