Extracting high-precision time

Report a typo

Suppose we have a home security system that logs every single time a cat is detected at the doorsteps. Our DataFrame looks like this:

            timestamp
0 2022-01-07 18:29:23
1 2022-02-06 08:01:42
2 2022-04-30 02:53:20
3 2022-02-15 17:39:10
4 2022-12-10 23:22:11

We want to manually review this type of activity by looking at the CCTV footage. Create a column calledextract_time, and store the hour, minute, and second as a single string in the HH:MM:SS format (or %H:%M:%S). Print out the resulting DataFrame.

Tip: Use dt.strftime with the proper format.

Write a program in Python 3
import pandas as pd

ts = ['01-07-2022 18:29:23', '02-06-2022 08:01:42', '30-04-2022 02:53:20', '15-02-2022 17:39:10', '12-10-2022 23:22:11', '05-09-2022 09:55:41', '03-02-2022 08:49:56', '12-10-2022 20:56:35', '06-09-2022 16:16:24', '21-08-2022 16:07:55', '17-12-2022 23:33:58', '27-12-2022 13:55:14', '16-07-2022 05:52:51', '16-05-2022 15:09:13']
df = pd.DataFrame({'timestamp': ts})
df['timestamp'] = pd.to_datetime(df['timestamp'], format="%d-%m-%Y %H:%M:%S")

#Your code here
___

Create a free account to access the full topic