我们如何将01-01-2011 19:00转换为平日,如星期一,星期二?在python?
问题描述:
我正在研究一个大熊猫数据框,其中有一列日期时间,现在我必须将其转换成平日。如何才能这样做?
I was working on a pandas dataframe where I had a column of datetime now I haveto convert it into Weekdays.How can I do this?
答
有一个datetime模块可能需要使用。
There is a datetime module you may want to use.
strptime和strftime 方法从 datetime module:
strptime and strftime methods from datetime module:
In [1]: import datetime
In [4]: datetime.datetime.strptime('01-01-2011 19:00','%d-%m-%Y %H:%M').strftime('%A')
Out[4]: 'Saturday'