如何将datetime格式中的年月提取出来(Pandas)

https://cloud.tencent.com/developer/ask/53091

新列分别显示年份和月份,可以这样做:

df['year'] = pd.DatetimeIndex(df['date']).year
df['month'] = pd.DatetimeIndex(df['date']).month

或者

df['year'] = df['date'].dt.year
df['month'] = df['date'].dt.month
    原文作者:微辣不香
    原文地址: https://blog.csdn.net/weixin_45659871/article/details/109544797
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞