Time series data

118 Views Asked by At

I have an Excel file and there are two columns in it, I want to combine them, but one of them is in datetime form and the other is object (actually time). What I want to do is convert the object one to datetime format.enter image description here

I've tried everything I can think of but I keep getting an error. Edit :enter image description here

import pandas as pd dataFrame = pd.read_excel('/content/drive/MyDrive/Colab Notebooks/data.xlsx') dataFrame.head() output: enter image description here and my error enter image description here

1

There are 1 best solutions below

5
On

If I'm understanding? You'd want to split "Time" column on space and take 0 index. Finally use .cat to concatenate the string columns together. Next .pop old columns and finally wrap it all in to_datetime.

df["Time"] = df["Time"].str.split(r"\s+").str[0]
df["Datetime"] = pd.to_datetime(df.pop("Date").astype(str).str.cat(df.pop("Time"), sep=" "))