How to convert 01:00:00 into integer in Python?

Question:

I need to convert a column of a dataframe that is in the format of HH:MM:SS as a string to an integer, for example: 01:00:00 to 01 or 1.

data = ['01:00:00','02:00:00','03:00:00','04:00:00']
df = pd.DataFrame(data, columns=['Numbers'])

I already tried the parameter
astype(int) but it does not accept the format 01:00:00

Asked By: Ismael Pauchner

||

Answers:

df["Numbers"] = df["Numbers"].map(lambda x: int(x[:2]))
Answered By: 0x0fba
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.