我正在使用存储库中的代码来预处理我的数据,并希望通过两个索引来区分python中的两个字符串,
start_parse
和
end_parse
。
我有两种类型的字符串:
类型1
20.0 +- 1.8% hemolysis at 50microM
11.2 +- 1.5% hemolysis at 50microM
18.1 +- 0.3% hemolysis at 50microM
20.9 +- 1.8% hemolysis at 50microM
29.0 +- 4.9% hemolysis at 50microM
另一个
类型2
是
'0% hemolysis at 312 to 0microg/ml'
例如
对于字符串类型1:
activity = '20.0 +- 1.8% hemolysis at 50microM'
解析器的起点和终点是:
activity[start_parse:end_parse]
' 50'
(Pdb) start_parse:end_parse
(Pdb) start_parse
27
(Pdb) end_parse
30
而对于字符串类型2,
“312至0微克/毫升时溶血率为0%”
的输出
activity[start_parse:end_parse]
' 312 to 0'
(Pdb) start_parse
15
(Pdb) end_parse
24
输出应该在其中
' 0'
不
' 312 to 0'
。
我想我不需要更改代码的这一部分:
if 'at' in activity:
if '~' in activity[activity.index('at'):] and activity.index('~') > activity.index('at'):
start_parse = activity.index('~') + 1
else:
start_parse = activity.index('at') + 2
else blabla:
如果字符串的开头是
0%
然后
启动分析
应该是
22
(
“0”
),并且在字符串开始时不会与另一个百分比混合,例如,
100% hemolysis at
?