'Series' object has no attribute 'strftime'
时间: 2023-09-11 20:10:33 浏览: 77
The error message "'Series' object has no attribute 'strftime'" indicates that you are trying to use the `strftime` method on a pandas Series object. However, the `strftime` method is only available for datetime objects in Python.
To fix this error, you need to convert the Series object to a datetime object first. Here's an example:
```python
import pandas as pd
# create a Series object of dates
dates = pd.Series(['2021-01-01', '2021-01-02', '2021-01-03'])
# convert the Series to a datetime object
dates = pd.to_datetime(dates)
# now you can use strftime on the datetime object
formatted_dates = dates.dt.strftime('%Y-%m-%d')
```
In this example, we first create a Series object of dates. We then convert the Series to a datetime object using the `pd.to_datetime` function. Finally, we can use the `strftime` method on the datetime object to format the dates as strings.
阅读全文