如何从Azure ml中的python中的给定日期中提取月份和年份

问题描述:

过去几天,我一直在用天蓝色ml工作.我想出了一个数据集,该数据集由以下格式的

I was working in azure ml for the past few days. I came up with a dataset which consists of date in the below format

mm/dd/yyyy hh:mm:ss

mm/dd/yyyy hh:mm:ss

我想通过在azure ml中编写python代码来从中提取月份和年份.我正在尝试以下代码:

I want to extract month and year from it by writing python code in azure ml. I am trying the following code:

def azureml_main(dataframe1 = None, dataframe2 = None):
    import pandas as pd
    dates = pd.to_datetime(dataframe1['Order Date'])
    dates = dates.apply(lambda x: x.strftime('%m-%d-%Y'))
    dataframe1['Order Date'] = dates
    # Execution logic goes here
    print('Input pandas.DataFrame #1:\r\n\r\n{0}'.format(dataframe1))

但是我收到一个错误消息,说NTType没有名为strftime的属性.谁能告诉我这里的问题是什么以及如何解决.

But I am getting an error saying that NTType there is no attribute with the name strftime. Can anyone tell me what's the issue here and how to solve it.

使用 .dt 访问datetime方法.

Use .dt to access the datetime methods.

例如:

dates = pd.to_datetime(data['Order Date']).dt.strftime('%m-%d-%Y')