1

with the new update on pandas I can't use this function that I used on on Datacamp learning course - (DAYOFWEEK doesn't exist anymore)

days_of_week = pd.get_dummies(dataframe.index.dayofweek,
                          prefix='weekday',
                          drop_first=True)

How can I change the syntax of my 'formula' to get the same results?

Sorry about the silly question but spent a lot of time here and I'm stuck...

Thanks in advance!

already tried just using the dataframe with index but doesn't get the days of the week on the get dummies\

used datetimeindex but messing up on the formulation as well

`days_of_week = pd.get_dummies(dataframe.index.dayofweek, prefix='weekday', drop_first=True)`

the dataframe is fairly big and need the outputs to get me the weekdays because I'm dealing with stock prices

Thiago AV
  • 55
  • 4
  • 1
    Guessing it isn't a datetime Index. Do this first: `pd.to_datetime(dataframe.index, errors='coerce').dayofweek` – cs95 Apr 05 '19 at 01:18
  • [pd.to_datetime(dataframe.index, errors='coerce').dayofweek] worked perfectly!! thanks a lot @coldspeed – Thiago AV Apr 05 '19 at 12:34

1 Answers1

0

Try weekday instead of dayofweek.

So

days_of_week = pd.get_dummies(dataframe.index.weekday,
                          prefix='weekday',
                          drop_first=True)

See docs below:

pandas.Series.dt.weekday

Bryce Ramgovind
  • 3,127
  • 10
  • 41
  • 72