我需要将Excel工作表的第一列转换为整数值。需要删除字符串(例如LP001005
,删除LP
,然后获取数字的其余部分)
我能够在单个变量上实现这一点。但是,我需要在Excel工作表上实现这一点。我的意思是将整个Excel转换为pandas中的数据框,提取Loan_ID
并进行转换(从LP001005
中删除LP
),然后使用数据框
>>> import re
>>> test_str = "Geeks4321"
>>> print("The original string is : " + str(test_str))
The original string is : Geeks4321
>>> res = [re.findall(r'(\d+)', test_str)[0] ]
>>> print("The tuple after the split of string and number : " + str(res))
The tuple after the split of string and number : ['4321']
>>>
Excel工作表如下所示:
LoanID Name
LP1401 Shubhra
LP1102 Ankit
LP1203 Sowmya
在Jupyter上试试这个:
您可以使用
.extract()
方法提取贷款ID的数字部分:相关问题 更多 >
编程相关推荐