仅将时间戳转换为月份名称

时间:2019-06-13 19:09:59

标签: python pandas timestamp

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

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

2 个答案:

答案 0 :(得分:0)

尝试:

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

答案 1 :(得分:0)

尝试:-

import datetime

# Getting month from the string
date_ = int("2019-06-13T14:22:28Z".split("-")[1])

# Extracting month name, from the number of the month
month_ = datetime.date(2000, int(date_), 1).strftime('%b')

print(month_)

输出:-

Jun
相关问题