How to Fix AttributeError: ‘Series’ object has no attribute ‘days’

Diagram of Series object has no attribute days

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

AttributeError - 'Series' object has no attribute 'days'

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

'Series' object has no attribute 'days'

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’

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.