20

I would like to get the weekday name for all my date. I have a pandas df which has a Date column formatted to datetime64[ns]

i have tried the following

data['Date'].dt.weekday_name

and I get the response

data['Date'].dt.weekday_name
Traceback (most recent call last):

  File "<ipython-input-207-e57074c4e346>", line 1, in <module>
    data['Date'].dt.weekday_name

AttributeError: 'DatetimeProperties' object has no attribute 'weekday_name'

Please help

John Doe
  • 637
  • 2
  • 7
  • 14
  • 1
    Does this answer your question? [Create a day-of-week column in a Pandas dataframe using Python](https://stackoverflow.com/questions/30222533/create-a-day-of-week-column-in-a-pandas-dataframe-using-python) – some_programmer Feb 21 '20 at 12:59
  • Thank you `df['my_dates'].dt.day_name()` – John Doe Feb 21 '20 at 13:05
  • 1
    The syntax you were trying to use `data['Date'].dt.weekday_name` is for PANDAS <= 0.22 (https://pandas.pydata.org/pandas-docs/version/0.22.0/generated/pandas.Series.dt.weekday_name.html) For newer pandas versions you should use `data['Date'].dt. day_name()` – shayms8 May 03 '20 at 13:18

1 Answers1

34

Maybe you can use day_name:

df['Date'].dt.day_name()
zipa
  • 27,316
  • 6
  • 40
  • 58