Search code examples
pythondataframegraphlabsframe

String object to dateTime object in SFrame


I have a huge dataset of around 20gb. I have read the data using graphlab.SFrame.read_csv(). I have a date column which is read as string in the format yyyy-dd-mm. But i want the column to be read as a datetime object. How can I do it?

I understand that one way is to iterate through each row and change it using python code. Is there any other way? May be faster?


Solution

  • import graphlab
    import datetime as dt
    sf = graphlab.SFrame.read_csv('input.csv') # dates in datestring column
    sf['datetime'] = sf['datestring'].apply(lambda x: dt.datetime.strptime(x, '%Y
    -%d-%m'))