I have a dataframe with the following format:
datetime.datetime(2021, 3, 23, 4, 59, tzinfo=tzoffset(None, -25200))
How can I find the day name? I tried .day_name()
, but for some reason when you have the zone data that doesn't work.
CodePudding user response:
Try using
object.strftime("%A")
where object refer to instance of datetime
This will return the day name as in name of days in week
CodePudding user response:
You can use weekday
to get a numeric day of the week. You can then use a dictionary to translate that to actual day names. Something like this:
from datetime import datetime
from dateutil.tz import tzoffset
date = datetime(2021, 3, 23, 4, 59, tzinfo=tzoffset(None, -25200))
days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
print(days[date.weekday()])