1

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:

enter image description here

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.

Steven
  • 119
  • 2
  • 4
  • 15

1 Answers1

1

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"})
Adam Oudad
  • 1,053
  • 7
  • 10
  • Thanks. df = df.astype({"column name": "datetime64"}) returned me a correct formatting. I updated my question - how to perform a tdelta operation in pandas or python? – Steven Jul 14 '20 at 13:23