Date and time extraction from Excel file in Python or Pandas

I have an Excel file with a column that contain both date and time in a single cells as follows:

2020-07-10T13:32:01+00:00

I'm wondering how to extract this cell, split date and time (that are separated by a T) and write them into 2 new columns Date and Time, and able to use them afterwards to, for example, do Time math operations.

I'd have a start from pandas:

    df = pd.read_excel('file.xlsx')
    def convert_excel_time(excel_time):
    return pd.to_datetime()

but I actually don't know if it is achievable with pandas.

If I have this:

I would like to calculate how many minutes passed (for the same date) for the same ID column (2nd column).

I guess I can use python tdelta, or is there a pandas alternative?

Thank you.

Topic time pandas python

Category Data Science


Pandas can parse most dates formats using

import pandas as pd
pd.to_datetime(df["name of your date column"])

You can also cast the desired column to datetime64 which is Numpy dtype

df = df.astype({"column name": "datetime64"})

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.