Answer the question
In order to leave comments, you need to log in
How to remove date from column?
I wanted to calculate the duration of events for the operation column so that only the time is given to me, and the date is also displayed to me, what should I do?
severstal_df['duration'] = pd.to_datetime(severstal_df['time'], format = '%H:%M:%S')
severstal_df
severstal_df = severstal_df.groupby('operation').duration.apply(lambda x: x.max() - x.min()).reset_index(name='duration')
severstal_df
Answer the question
In order to leave comments, you need to log in
This field is not a date, but a date range (Timedelta), because it was obtained by subtracting 2 dates. He doesn't have "just time". To take only the time from it, you must first cast it to the date type. For example, like this (we add this time range to today's date), then you can already display the time separately without a date:
(pd.Timestamp('today').normalize()+severstal_df['duration']).dt.time
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question