📌  相关文章
📜  将 pandas 日期时间转换为日、工作日、月 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:21.291000             🧑  作者: Mango

代码示例1
#Convert datetime column/series to hour of the day. NB: Column must be in datetime format.
df['hour'] = df['column_name'].dt.hour
#Convert datetime column/series to day of the week
df['day'] = df['column_name'].dt.weekday
#Convert datetime column/series to month
df['month'] = df['column_name'].dt.month
#Convert datetime column/series to year
df['year'] = df['column_name'].dt.year
#NB: Weekday/Month will be in int. Eg. for months, January=1, February=2...etc,