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
CodePudding user response:
df["Numbers"] = df["Numbers"].map(lambda x: int(x[:2]))