简体   繁体   English

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

[英]How to extract month and year from given date in python in azure ml

I was working in azure ml for the past few days. 过去几天,我一直在使用天蓝色ml。 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

I want to extract month and year from it by writing python code in azure ml. 我想通过在azure ml中编写python代码从中提取月份和年份。 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))

But I am getting an error saying that NTType there is no attribute with the name strftime. 但是我收到一个错误消息,说NTType没有名称为strftime的属性。 Can anyone tell me what's the issue here and how to solve it. 谁能告诉我这里的问题是什么以及如何解决。

Use .dt to access the datetime methods. 使用.dt访问datetime方法。

Ex: 例如:

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

您可以使用SQL转换使用SQL查询来强制转换您的日期时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM