how to separate date and time in python

Solutions on MaxInterview for how to separate date and time in python by the best coders in the world

showing results for - "how to separate date and time in python"
Lya
12 Mar 2017
1import pandas as pd
2df = pd.DataFrame({'datetime':pd.date_range('2020-01-01 07:10',periods=6)})
3print("DataFrame is:\n", df)
4df['date'] = pd.to_datetime(df['datetime']).dt.date
5df['time'] = pd.to_datetime(df['datetime']).dt.time
6print("Date-time-hour-minutes :\n", df)
Bianca
19 Jan 2021
1for d in df['datetime']:
2   df['date'] = d.date()
3   df['time'] = d.time()