Diagram
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)
Output
How to fix it?
Here’s an example of how you can extract the number of days from a Series containing Timedelta
objects:
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)
Output
That’s it.
Related posts
AttributeError: ‘Series’ object has no attribute ‘merge’
AttributeError: ‘Series’ object has no attribute ‘reshape’
AttributeError: ‘Series’ object has no attribute ‘strftime’
AttributeError: ‘Series’ object has no attribute ‘lower’
AttributeError: ‘Series’ object has no attribute ‘explode’

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.