BK_LIST =
["05 Sep 2020 OPENING BALANCE $30,152.02CR",
"05 Sep Transfer to xxXXXX XXXXXXXXX app 100.00 $ $30,052.02CR",
"27 Oct Transfer to xxXXXX XXXXXXXXX app 100.00 $ $31,800.06CR",
"01 Nov Credit Interest $1.32 $31,601.38CR",
"02 Nov Transfer to xxXXXX XXXXXXXXX app 51.00 $ $31,550.38CR",
"30 Dec Transfer to xxXXXX XXXXXXXXX app 100.00 $ $27,800.00CR",
"31 Dec Transfer to xxXXXX XXXXXXXXX app 100.00 $ $29,000.00CR",
"01 Jan Credit Interest $1.27 $29,001.27CR",
"26 Feb Transfer to xxXXXX XXXXXXXXX app 100.00 $ $28,900.00CR",
"03 Mar Transfer to xxXXXX XXXXXXXXX app 100.00 $ $28,700.08CR",
"04 Mar 2021 CLOSING BALANCE $28,700.08 CR"
]
字符串
我想在日期月份(05 Sep)后插入年份(2020)。预期输出:
27 Oct 2020, 01 Jan 2021 ...
型
1.我生成了一个缩写列表。2020年和2021年的月份和年份。
mth_yr_list =['Jan 2020', 'Feb 2020', 'Mar 2020', 'Apr 2020', 'May 2020', 'Jun 2020', 'Jul 2020', 'Aug 2020', 'Sep 2020', 'Oct 2020', 'Nov 2020', 'Dec 2020', 'Jan 2021', 'Feb 2021', 'Mar 2021', 'Apr 2021', 'May 2021', 'Jun 2021', 'Jul 2021', 'Aug 2021', 'Sep 2021', 'Oct 2021', 'Nov 2021', 'Dec 2021']
型
1.我从BK_LIST创建了一个月的列表。
list_of_mths =["Sep","Oct","Nov","Dec","Jan","Feb","Mar"]
My tried program:
jac =[]
for mth in list_of_mths:
for mth1 in mth_yr_list:
mth2 = mth1[:3].strip()
if mth ==mth2:
jac.append(mth1)
mth_yr_list.remove(mth1)
print(jac)
型
输出量:
['Sep 2020', 'Sep 2021', 'Oct 2020', 'Oct 2021', 'Dec 2021']
型
预期输出:
['Sep 2020', 'Oct 2020', 'Nov 2020','Dec 2020','Jan 2021','Feb 2021', 'Mar 2021']
型
2条答案
按热度按时间eimct9ow1#
您可以尝试:
字符串
印刷品:
型
31moq8wy2#
使用Pandas
字符串
返回:
型
您可以使用dataframe进一步操作:
型