How to convert hours & minutes to minutes

Hi,i have a column in database, dtype = object

Running_Time
2 h 3 min
1 h
30 min

I want to create a new column in df ‘Minutes’ that converts this column over to minutes
Minutes
123
60
30

I think you are looking for something like this…tell me if it is want you want…
I would encourage you to go through the code and understand what’s happening and maybe try a better approach to do the conversion…

Hi vinay, bingo! Thank you for this.

Just one more thing if the dataset contains more values like [‘3h’ , ‘56min’].
I am getting ‘list index out of range’ error because of such values.

Actually the code only works for the format where the time is given like this…
"3 h" and "56 min"
And you have format like…
"3h" and "56min"

I hope you can see the difference…

You can modify the function convert(time) to handle various cases and get the desired results…
If you want I can give you the code…but first you should try it yourself…

Hey…
This should work…

image

2 posts were merged into an existing topic: What are the most common languages used by students? How does the list compare with the most common languages used by professional developers