Python .month 格式是 numeric(1) 想要 MMM(Jan)

标签 python pandas

我正在尝试创建一个列,以便从 Trade Trade Dt 列中仅检索月份统计数据。

我希望下面的 MMM 格式为数字。

map_cat['Trade Month'] = pd.DatetimeIndex(map_cat['Trade Trade Dt']).month

最佳答案

另一种选择:

map_cat['Trade Month'] = pd.DatetimeIndex(map_cat['Trde Trade Dt']).month_name().str[:3]

关于Python .month 格式是 numeric(1) 想要 MMM(Jan),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60378587/

相关文章:

python - 将包含 utf-8 文本和 URL 的文本列导出 Pandas 数据框到 Excel

python - 对填充列表的 DataFrame 的每一列应用一个函数

python - Pandas `to_csv` 无法设置引号

python - 在 Python 3.6 中导入库 "modin"时出错

python - 如何使用 matplotlib 制作新的形状补丁?

python - 虚线箭头向下规则

python - 如何更改 Elasticsearch 8 中不推荐使用 'body' 参数的语法?

python - 客户端排序查询集,Django + TwitterBoostrap

python - 对几个特定频率取 fft 和 ifft

python - 在 Python 中创建严格递增列表的最快方法