I have a timestamp
column where the timestamp is in the following format
2016-06-16T21:35:17.098+01:00
I want to extract date
Do this first:
df['time'] = pd.to_datetime(df['timestamp'])
Before you do your extraction as usual:
df['dates'] = df['time'].dt.date
If date is in string form then:
import datetime
# this line converts the string object in Timestamp object
df['DateTime'] = [datetime.datetime.strptime(d, "%Y-%m-%d %H:%M") for d in df["DateTime"]]
# extracting date from timestamp
df['Date'] = [datetime.datetime.date(d) for d in df['DateTime']]
# extracting time from timestamp
df['Time'] = [datetime.datetime.time(d) for d in df['DateTime']]
If the object is already in the Timestamp format then skip the first line of code.
%Y-%m-%d %H:%M
this means your timestamp object must be in the form like 2016-05-16 12:35:00
.