首页 > 解决方案 > 仅将时间戳转换为月份名称

问题描述

我想将数据框列中的每个时间戳更改为月份名称。

date =[]
month=0
for j in clean_data['created_at']:
    date.append(j)
    month = time.strftime("%b",time.gmtime(date))
print(month)

我有以下错误:

TypeError:需要一个整数(获取类型 str)

我的预期输出是“一月,二月,三月等......”。例如,我 2019-06-13T14:22:28Z只想成为Jun

标签: pythonpandastimestamp

解决方案


尝试:

clean_data['created_at']= pd.to_datetime(clean_data['created_at'])
clean_data['created_at'].dt.month_name().str[:3]

推荐阅读