Datetimeproperties object has no attribute days

2

Posted by8 months ago

Datetimeproperties object has no attribute days

import pandas as pd
df = pd.read_csv('some_frame.csv')
frame = pd.DataFrame(df)


frame['Seconds'] = frame['Time'].dt.total_seconds()

>>AttributeError: 'DatetimeProperties' object has no attribute 'total_seconds'

Documentation. What I do wrong?

5 comments

100% Upvoted

Log in or sign up to leave a comment

Log InSign Up

Datetimeproperties object has no attribute days

level 1

· 8 mo. ago

This method is available directly on TimedeltaArray, TimedeltaIndex and on Series containing timedelta values under the .dt namespace

Do you have datetime values or timedelta values.

https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.total_seconds.html

1

level 2

Op · 8 mo. ago

ohh I see. I tried to do after to_datetime it's another data type?

1

level 2

Op · 8 mo. ago

I have a string how do I convert it to duration?

1:31.097

mm : ss . millisecond > ss . millisecond

1

Continue this thread 

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

Asked 26-03-2022

python

0

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

Share a link to this question

Link Copied!

Copy link

Datetimeproperties object has no attribute days

khyativerma

asked 26-03-2022


2 Answers


0

change:

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

To

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

Share a link to this question

Link Copied!

Copy link

Datetimeproperties object has no attribute days

khyativerma

answered 26-03-2022


0

use the following code.

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

Share a link to this question

Link Copied!

Copy link

Datetimeproperties object has no attribute days

khyativerma

answered 26-03-2022


You need to login first then you can post Your Answer Log in Sign up

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    Series.dt can be used to access the values of the series as datetimelike and return several properties. Pandas Series.dt.day attribute return a numpy array containing the day of the datetime in the underlying data of the given series object.

    Syntax: Series.dt.day

    Parameter : None

    Returns : numpy array

    Example #1: Use Series.dt.day attribute to return the day of the datetime in the underlying data of the given Series object.

    import pandas as pd

    sr = pd.Series(['2012-10-21 09:30', '2019-7-18 12:30', '2008-02-2 10:30',

                    '2010-4-22 09:25', '2019-11-8 02:22'])

    idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']

    sr.index = idx

    sr = pd.to_datetime(sr)

    print(sr)

    Output :

    Datetimeproperties object has no attribute days

    Now we will use Series.dt.day attribute to return the day of the datetime in the underlying data of the given Series object.

    result = sr.dt.day

    print(result)

    Output :

    Datetimeproperties object has no attribute days

    As we can see in the output, the Series.dt.day attribute has successfully accessed and returned the day of the datetime in the underlying data of the given series object.
     
    Example #2 : Use Series.dt.day attribute to return the day of the datetime in the underlying data of the given Series object.

    import pandas as pd

    sr = pd.Series(pd.date_range('2012-12-12 12:12'

                           periods = 5, freq = 'H'))

    idx = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5']

    sr.index = idx

    print(sr)

    Output :

    Datetimeproperties object has no attribute days

    Now we will use Series.dt.day attribute to return the day of the datetime in the underlying data of the given Series object.

    result = sr.dt.day

    print(result)

    Output :

    Datetimeproperties object has no attribute days

    As we can see in the output, the Series.dt.day attribute has successfully accessed and returned the day of the datetime in the underlying data of the given series object.