close

[Solved] AttributeError: ‘Series’ object has no attribute ‘days’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AttributeError: ‘Series’ object has no attribute ‘days’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AttributeError: ‘Series’ object has no attribute ‘days’ Error Occurs?

Today I get the following error AttributeError: ‘Series’ object has no attribute ‘days’ in python.

How To Solve AttributeError: ‘Series’ object has no attribute ‘days’ Error ?

  1. How To Solve AttributeError: 'Series' object has no attribute 'days' Error ?

    To Solve AttributeError: 'Series' object has no attribute 'days' Error DataFrame column is a Series, and for Series you need dt.accessor to calculate days (if you are using a newer Pandas version).

  2. AttributeError: 'Series' object has no attribute 'days'

    To Solve AttributeError: 'Series' object has no attribute 'days' Error DataFrame column is a Series, and for Series you need dt.accessor to calculate days (if you are using a newer Pandas version).

Solution 1

While subtracting the dates you should use the following code.

df = pd.DataFrame([ pd.Timestamp('20010101'), pd.Timestamp('20040605') ])
(df.loc[0]-df.loc[1]).astype('timedelta64[D]')

So basically use .astype('timedelta64[D]') on the subtracted column.

Solution 2

DataFrame column is a Series, and for Series you need dt.accessor to calculate days (if you are using a newer Pandas version). You can see docs here

So, you need to change:

df['days'] = float(df['delta'].days)

To

df['days'] = float(df['delta'].dt.days)

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read