AttributeError: 'numpy.float64' object has no attribute 'strftime'
时间: 2023-09-18 08:13:20 浏览: 305
This error occurs when you try to use the `strftime()` method on a `numpy.float64` object.
The `strftime()` method is used to convert a date or time object into a string representation. However, `numpy.float64` is a numeric data type and does not have any datetime-related attributes or methods.
To fix this error, make sure that you are passing a valid date or time object to the `strftime()` method. If you are trying to convert a numpy array of dates, you can first convert it to a datetime object using the `datetime` module and then apply the `strftime()` method to it.
Here is an example:
```python
import numpy as np
from datetime import datetime
# create a numpy array of dates
dates = np.array(['2022-01-01', '2022-01-02', '2022-01-03'], dtype='datetime64')
# convert the numpy array to a list of datetime objects
dates_list = [datetime.utcfromtimestamp(date.tolist()/1e9) for date in dates]
# apply the strftime() method to the datetime objects
formatted_dates = [date.strftime('%Y-%m-%d') for date in dates_list]
print(formatted_dates) # ['2022-01-01', '2022-01-02', '2022-01-03']
```
In this example, we first create a numpy array of dates and then convert it to a list of datetime objects. Finally, we apply the `strftime()` method to each datetime object in the list to get the formatted dates.
阅读全文