将字符串值从字典映射到Pandas中的整数

时间:2019-11-12 17:00:55

标签: python-3.x datetime

如何从今天的日期中提取该月和上个月的文本值?我在下面获取整数值。

today = datetime.date.today()
first = today.replace(day=1)
current_month = first - datetime.timedelta(days=1)
current_month = current_month.strftime("%m")
current_month = int(current_month)
last_month = current_month - 1

我有一个包含数字和月份值的文件,因此我正在考虑使用该文件映射到整数。看起来像是一个数据框:

Number  Month
1   January
2   February
3   March
4   April
5   May
6   June
7   July
8   August
9   September
10  October
11  November
12  December

0 个答案:

没有答案