如何从Azure ml中的python中的给定日期中提取月份和年份 [英] How to extract month and year from given date in python in azure ml

查看:111
本文介绍了如何从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')

这篇关于如何从Azure ml中的python中的给定日期中提取月份和年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆