I want to transform my DataFrame with dates to the specific weekday.
df=
Date
0 2019-09-05
1 2018-09-07
2 2017-09-02
Another column now should say e.g. Monday, Tuesday etc. for each day. How can I run this method in a Dataframe?
I want to transform my DataFrame with dates to the specific weekday.
df=
Date
0 2019-09-05
1 2018-09-07
2 2017-09-02
Another column now should say e.g. Monday, Tuesday etc. for each day. How can I run this method in a Dataframe?
You can do the following using pandas.Series.dt.day_name
df['Day'] = df['Date'].dt.day_name()
Giving output:
>>> df
Date Day
0 2019-09-05 Thursday
1 2018-09-07 Friday
2 2017-09-02 Saturday
As another option you can convert dates to day name using .strftime
df['Day'] = df['Date'].strftime('%A')
Please, note that dates must be in datetime format to perform this.
You can also find Python's strftime directives here