python/pandas:将month int转换为月份名称 [英] python/pandas: convert month int to month name
本文介绍了python/pandas:将month int转换为月份名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现的大多数信息都不在python> pandas> dataframe中,因此是问题所在.
Most of the info I found was not in python>pandas>dataframe hence the question.
我想将1到12之间的整数转换为缩写的月份名称.
I want to transform an integer between 1 and 12 into an abbrieviated month name.
我有一个df,看起来像:
I have a df which looks like:
client Month
1 sss 02
2 yyy 12
3 www 06
我希望df看起来像这样:
I want the df to look like this:
client Month
1 sss Feb
2 yyy Dec
3 www Jun
推荐答案
您可以通过组合calendar.month_abbr
和df[col].apply()
import calendar
df['Month'] = df['Month'].apply(lambda x: calendar.month_abbr[x])
这篇关于python/pandas:将month int转换为月份名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文