AttributeError: ‘Series’ object has no attribute ‘days’ error occurs when you are “trying to access a days attribute on a Pandas Series object, but such an attribute doesn’t exist.”
To fix the AttributeError: ‘Series’ object has no attribute ‘days’ error, use the “.dt” accessor along with the “days” property.
If you are working with a Series containing date or time deltas and want to extract the number of days, use the “.dt” accessor and the “days” property.
Reproduce the error
import pandas as pd # Create a Series with Timedelta objects s = pd.Series(pd.to_timedelta(['1 days', '2 days', '3 days'])) days = s.days print(days)
How to fix it?
Here’s an example of how you can extract the number of days from a Series containing
import pandas as pd # Create a Series with Timedelta objects s = pd.Series(pd.to_timedelta(['1 days', '2 days', '3 days'])) # Extract the number of days using the dt accessor days = s.dt.days print(days)