i have already tried these but by this we can only get hour/minute/second but not both minute and second
In[7]:
df['B'] = df['A'].dt.components['hours']
df
Out[7]:
A B
0 02:00:00 2
1 01:00:00 1
from this timedelta format
0 0 days 00:02:02.246000
1 0 days 00:01:59.127000
i need only minutes and seconds, how to get it as below
02:02
01:59
You can convert the timedelta to total seconds and use divmod function to extract minutes and seconds from the total seconds.
Edit: Removed lambda function from the first operation.
df['sec'] = df['A'].dt.total_seconds().astype(int)df['B'] = df.apply(lambda row: str(divmod(divmod(row['sec'], 3600)[1], 60)[0]).zfill(2)+':'+str(divmod(divmod(row['sec'], 3600)[1], 60)[1]).zfill(2), axis=1)