无法在numpy.datetime64上调用strftime,无定义 [英] Can't call strftime on numpy.datetime64, no definition

查看:393
本文介绍了无法在numpy.datetime64上调用strftime,无定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个想要表示为字符串的datetime64 t.

I have a datetime64 t that I'd like to represent as a string.

当我这样调用strftime时,出现此错误:

When I call strftime like this t.strftime('%Y.%m.%d') I get this error:

AttributeError: 'numpy.datetime64' object has no attribute 'strftime'

我想念什么?我正在使用Python 3.4.2和Numpy 1.9.1

What am I missing? I am using Python 3.4.2 and Numpy 1.9.1

推荐答案

使用以下代码:

import pandas as pd 
t= pd.to_datetime(str(date)) 
timestring = t.strftime('%Y.%m.%d')

这篇关于无法在numpy.datetime64上调用strftime,无定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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