How to extract data from Dataset?

I have a column in my dataset, which has the listening time of audible books. The data is stored like 10 hours and 43 minutes

How to extract them and change it into minutes, in a python dataframe?

I have used
audiob_adv['time'] = audiob_adv['Listening Time'].str.extract('(\d\d)')

But this is not working correctly.

An “regex-like” strings require an r before them. Example:
r'\d+[abc]'
Anyway your solution will not work probably. You need to split the hours and minutes into separate capture groups. Also you need to capture more than one symbol with +. I would try:
r'(\d+)\D*(\d+)'
But I have no idea if it’s always hours and minutes or there are exceptions (like just minutes or just hours).

How to extract total number of entries from a particular column in pandas ??
Please Suggest ! :slight_smile:

This is what I have done!
To know more, u should look into some regex tutorials. :slight_smile:

temp_df = audiob_adv['Listening Time'].str.extract(r'(\d+)[^\d]+(\d+)').astype('float64')
audiob_adv["Time"] = temp_df.iloc[:,0]*60 + temp_df.iloc[:,1]

1 Like

Hi All,

I need to convert 12.03.25 i.e yy-dd-mm into pandas datatime.

I need help to convert this format into datetime in Pandas for course project.

Thanks in advance.