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

convert String type data into Int type data

I have data in the format:

0    20:30
1    17:05
2    17:28
3    14:12
4    19:58
..     ...
176  15:57
177  19:02
178  17:52
179  19:39

And it’s Dtype is Str type. How can I convert this str type (hour, minute) data into int type and use only the time part separately?

How can I convert this str type (hour, minute) data into int type and use only the time part separately?

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 :

def str_to_int_list(mylist):
   newlist = []
   for value in mylist:
       hr, min_ = value.split(":")
       newlist.append(int(hr)*60+int(min_))
   return newlist
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