0

I have the following Dataframe: Dataframe

Now i want to convert the column "ABZEIT" to time format. So the first rows would be:

13:05 15:40 14:20 16:30 07:40 12:05 17:15

FObersteiner
  • 22,500
  • 8
  • 42
  • 72
luscgu00
  • 43
  • 6
  • Here is how :) https://stackoverflow.com/questions/62070759/how-to-convert-string-hhmm-to-time-in-python – Tocy777 Dec 12 '22 at 08:34
  • 1
    @Tocy777 older dupe: [Convert number to time in Python](https://stackoverflow.com/questions/30070548/convert-number-to-time-in-python) - there are probably more. – FObersteiner Dec 12 '22 at 09:02

1 Answers1

0

A solution that first defines a to_time() function then apply it to the dataframe by using map().

from datetime import time

def to_time(t: int) -> time:
    t = f"{t:04}"  # add the leading zero if needed
    return time(int(t[:2]), int(t[2:]))

df["ABZEIT"] = df["ABZEIT"].map(to_time)
0x0fba
  • 1,520
  • 1
  • 1
  • 11