回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我已经构建了这个小代码来从字符串(字符串也可以是1页)中获取pkeys(数字),然后按行显示唯一的pkeys。例如,如果字符串为“失败:无法检索市场数据:[工具48021088、1029755的历史相关性<br/>
大于2M,仪器48021088、102975554454的历史相关性大于2M,加载结构化产品市场数据时出错“</p>
<p>输出应为:
48021088
1029755
5445454</p>
<p>但是现在我的输出是[480210810297552]
544545]</p>
<p>注:不应将字符串“2M”中的2作为pkey,即2个月</p>
<p>此外,每当我在这段代码中复制一个长字符串时,我必须在每一行的末尾放\以使其运行。如果我从outlook或任何其他源中复制一个字符串并粘贴到这段代码中,我能做些什么,它应该自动格式化它并自行插入\吗</p>
<p><a href="https://i.stack.imgur.com/aFU9h.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aFU9h.jpg" alt="enter image description here"/></a></p>
<pre><code>import re
import numpy as np
import pandas as pd
regex = ('\d+')
match = re.findall(regex, 'Failure: Cannot retrieve market data: [Historical correlation for instruments 48021088, 1029755 \
is older than 2M, Historical correlation for instruments 48021088, 1029755 is older than 2M, Error while loading Structured Product market data \
Failure: Cannot retrieve market data: [Historical correlation for instruments 52598110, 35602558 is older than 2M, Historical correlation for instruments \
52598110, 35602558 is older than 2M, Historical correlation for instruments 52598110, 35602558 is older than 2M, Historical correlation for instruments 52598110, \
35602558 is older than 2M, Error while loading Structured Product market data \
Failure: Cannot retrieve market data: [Historical correlation for instruments 48021088, 1029755 is older than 2M, Historical correlation for instruments 48021088, 1029755 \
is older than 2M, Error while loading Structured Product market data \
Failure: Cannot retrieve market data: [Historical correlation for instruments 612292, 52598110 is older than 2M, Historical correlation for instruments 612292, 52598110 is \
older than 2M, Historical correlation for instruments 612292, 52598110 is older than 2M, Historical correlation for instruments 612292, 52598110 is older than 2M, \
Error while loading Structured Product market data \
Failure: Cannot retrieve market data: [Historical correlation for instruments 489459, 104322960 is older than 2M, Historical correlation for instruments 489459, \
104322960 is older than 2M, Historical correlation for instruments 489459, 104322960 is older than 2M, Historical correlation for instruments 489459, \
104322960 is older than 2M, Error while loading Structured Product market data')
res = list(map(int,match))
x = res
# print(str(x))
unique_numbers = list(set(x))
print(np.transpose(unique_numbers))
</code></pre>