Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 650
Dreams Avatar asked Nov 26 '15 17:11

Dreams


People also ask

How do you convert a string to a datetime object in Python?

We can convert a string to datetime using strptime() function. This function is available in datetime and time modules to parse a string to datetime and time objects respectively.

How do I convert a string to a date in pandas?

Use pandas.to_datetime() method is used to change String/Object time to date type (datetime64[ns]). This method is smart enough to change different formats of the String date column to date.

How do I convert a string to a timestamp in python?

Import the datetime library. Use the datetime. datetime class to handle date and time combinations. Use the strptime method to convert a string datetime to a object datetime.

How do I convert Yyyymmdd to date in python?

yyyy-mm-dd stands for year-month-day . We can convert string format to datetime by using the strptime() function. We will use the '%Y/%m/%d' format to get the string to datetime.


1 Answers

There's actually a built-in method for this in graphlab.SArray. Like Greg Whittier's answer, suppose your original date column is called datestring.

import graphlab
sf = graphlab.SFrame.read_csv('input.csv')
sf['datetime'] = sf['datestring'].str_to_datetime('%Y-%d-%m')
like image 123
papayawarrior Avatar answered Sep 20 '22 07:09

papayawarrior