How to parse out date and time from pandas dataframe column in python?

Viewed 28

I have a dataframe column that looks like the following:

df['Date'] column

I'm trying to parse out the date and time from this column so that I can add both to two separate columns. How would I go about doing that?

1 Answers

You can use a list comp to separate and then use zip to unpack into columns.

df["Date"] = pd.to_datetime(df["Date"])
df["Date"], df["Time"] = zip(*[(x.date(), x.time()) for x in df["Date"]])
Related