sách gpt4 ăn đã đi

python / Pandas: chuyển tháng int thành tên tháng

In lại Tác giả: IT Lão Cao 更新时间:2023-10-28 20:59:18 28 4
mua khóa gpt4 giày nike

我发现的大部分信息都不在 python>pandas>dataframe 中,因此是这个问题。

我想将 1 到 12 之间的整数转换为缩写的月份名称。

我有一个 df,它看起来像:

   client Month
1 sss 02
2 yyy 12
3 www 06

我希望 df 看起来像这样:

   client Month
1 sss Feb
2 yyy Dec
3 www Jun

câu trả lời hay nhất

您可以通过结合使用 calendar.month_abbrdf[col].apply()

有效地做到这一点
import calendar
df['Month'] = df['Month'].apply(lambda x: calendar.month_abbr[x])

关于 python / Pandas : convert month int to month name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37625334/

28 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress