Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

df["Numbers"] = df["Numbers"].map(lambda x: int(x[:2]))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading