0

I would like to convert my dataframe from this string to a usable date-time format

01/May/2016:06:38:13 +0100

I'm currently using Python V 3.5.1 :: Anaconda 4.0.0(64-bit)

SerialDev
  • 2,777
  • 20
  • 34

2 Answers2

1
import time
from time import mktime
from datetime import datetime
df.time = df.time.apply(lambda x: datetime.fromtimestamp(mktime(time.strptime(x, '%d/%b/%Y:%I:%M:%S %z'))))

http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior How do you convert a Python time.struct_time object into a datetime object?

Community
  • 1
  • 1
1

From Joris comment this should do it using dateutil:

from dateutil.parser import parse
a='01/May/2016:06:38:13 +0100'

In[27]:parse(a.replace(':', ' ', 1))
Out[27]: datetime.datetime(2016, 5, 1, 6, 38, 13, tzinfo=tzoffset(None, 3600))
Community
  • 1
  • 1
shivsn
  • 7,680
  • 1
  • 26
  • 33