'numpy.int64' object has no attribute 'strftime'
时间: 2023-09-10 18:14:14 浏览: 282
This error occurs when we try to use the strftime() method on a numpy.int64 object. strftime() is a method available in Python's datetime module and is used to convert a datetime object to a string representation based on a given format.
To resolve this error, we need to convert the numpy.int64 object to a datetime object before using the strftime() method. We can do this by using the datetime.fromtimestamp() method or the datetime.utcfromtimestamp() method, which take a timestamp as input and return a datetime object.
Here's an example of how we can convert a numpy.int64 object to a datetime object and then use the strftime() method:
```
import numpy as np
import datetime
# create a numpy.int64 object representing a timestamp
timestamp = np.int64(1618867200)
# convert the timestamp to a datetime object
dt_object = datetime.datetime.utcfromtimestamp(timestamp)
# use the strftime() method to format the datetime object as a string
formatted_date = dt_object.strftime("%Y-%m-%d")
# print the formatted date
print(formatted_date)
```
Output:
```
2021-04-20
```
阅读全文