Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Azure by (45.3k points)

I've got a dataset at hand with a column of DateTime in String format, eg.

a = 'Tue Sep 22 1998 00:00:00 GMT+0000 (Coordinated Universal Time)'

and a is just a value from the column.

If I use Metadata Editor in Azure Machine Learning Studio, it won't work and will complain that it can't do the conversion (from String to DateTime). I guess it's something to do with the format. So I'm trying the following:

a = str(a)[:10]+','+str(a)[10:15]

#'Tue Sep 22, 1998'

Now .NET surely can do the conversion, I mean by a method like Convert.ToDateTime(). However, when I visualized the output of the Python script, I found the String has been changed into 'Tue Sep 22, 1998 None,', which is quite weird. Does anyone know what's wrong with it? I'm attaching the excerpt of python code down below:

def azureml_main(dataframe1 = None, dataframe2 = None):

  dataframe1['timestamp'] = dataframe1['timestamp'].apply(lambda a: str(a)[:10]+','+str(a)[10:15])

  return dataframe1,

1 Answer

0 votes
by (16.8k points)

I use Python for date format normalization. You have to change to string before returning a dataFrame because underlying R will thrown an exception

def azureml_main(dataframe1 = None, dataframe2 = None):

    import pandas as pd

    dates = pd.to_datetime(dataframe1['DATE'])

    dates = dates.apply(lambda x: x.strftime('%Y-%m-%d'))

    dataframe1['DATE'] = dates

return dataframe1,

Then I use a Metadata Editor to change the type to DateTime.

Browse Categories

...