Reputation: 25
Could you help me on this issue please?
I am recently upgraded my pandas to version 1.0.0 and one of my code stopped working. More specifically, I used to get the weekday_name property from the date using
s.dt.weekday_name
Now, since pandas upgraded, I got this error: AttributeError: 'DatetimeProperties' object has no attribute 'weekday_name'
I check the document and it seemed this property change to 'day_name' so I tried:
s.dt.day_name
However, the output doesn't turn out as expected.
bound method PandasDelegate._add_delegate_accessors.<locals>._create_delegator_method.<locals>.f of <pandas.core.indexes.accessors.DatetimeProperties object at 0x0000021670C93748
I would much appreciated if you could let me know the workaround.
Example to reproduce:
s = pd.date_range('2016-12-31', '2017-01-08', freq='D').to_series()
s.dt.weekday_name
s.dt.day_name
Upvotes: 2
Views: 2805
Reputation: 59549
Series.dt.day_name
is implemented as a method, not an attribute. As such you need to call it with ()
s.dt.day_name()
#2016-12-31 Saturday
#2017-01-01 Sunday
#2017-01-02 Monday
#2017-01-03 Tuesday
#2017-01-04 Wednesday
#2017-01-05 Thursday
#2017-01-06 Friday
#2017-01-07 Saturday
#2017-01-08 Sunday
#Freq: D, dtype: object
Unlike the old, Series.dt.weekday_name
attribute, you can now pass arguments which allow you to change the language.
s.dt.day_name('Danish')
#2016-12-31 Lørdag
#2017-01-01 Søndag
#2017-01-02 Mandag
#2017-01-03 Tirsdag
#2017-01-04 Onsdag
#2017-01-05 Torsdag
#2017-01-06 Fredag
#2017-01-07 Lørdag
#2017-01-08 Søndag
#Freq: D, dtype: object
Upvotes: 5