G
G
gowwa1232021-06-16 18:37:07
Python
gowwa123, 2021-06-16 18:37:07

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

60ca17d0c2d85422573313.png
60ca1808ef54e333923350.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
o5a, 2021-06-17
@gowwa123

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

Z
zexer, 2021-06-16
@zexer

.time()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question