【问题标题】:Convert datetime to month and year only in Pandas [duplicate]仅在 Pandas 中将日期时间转换为月份和年份 [重复]
【发布时间】:2021-12-18 13:33:03
【问题描述】:

我有一个这样格式的专栏:

开业日期/时间

2014-09-01 00:17:00

2014-09-18 18:55:00

我已使用以下函数将其转换为日期时间

df['Date/Time Opened'] = pd.to_datetime(df['Date/Time Opened'])

如何将其转换为“mm/yyyy”格式,以便按频率/计数将其绘制在图表中?

【问题讨论】:

标签: python pandas datetime


【解决方案1】:

试试:

df['Date/Time Opened'].dt.to_period('M')

【讨论】:

    猜你喜欢
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 2014-12-29
    • 2014-03-25
    • 2018-12-24
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    相关资源
    最近更新 更多