How to Convert a Pandas Column having duration details in string format (ex:1hr 50m) into a integer column with value in minutes Lets say i have the following data like below:

  import pandas as pd
    import numpy as np
    df = pd.DataFrame({'Duration': ['1h 50m', '50m', '3h', '2h 30m', '5h', '60m']
                  })
    df


Generated Output:



Column Created in pandas data frame contains duration details in string format i.e (1h 50m,50m,3h etc). I need to know how to convert this column into an integer with the value displayed in minutes (110,50,180).
One liner:

df['Duration']=  df['Duration'].str.replace("h", '*60').str.replace(' ','+').str.replace('m','*1').apply(eval)


Basically, it converts your string into an equation in string format and evaluates it.

Hope it helps!