文本挖掘 python 个键
text mining python keys
我有一个多行文件,制表符分隔,第二列可能包含(或不包含)一些关键字,
Place1______________fish
Place2______________fishing someting
Placexx_____________something missing
Place_somwhere______something else missing
EHDN_______________fishing something
HDGFE______________looking for something
(线条很难看,但我无法使数据看起来像 table)
每当该行包含 'something missing' 时,我都需要在该行的末尾添加注释,例如“此处需要操作”;
我试过类似的东西:
pattern="something missing"
OUT=open('/Users/user/output.tab','w')
for line in file:
field=line.split('\t')
if pattern in field[1]:
action = ';'.join("ACTION NEEDED")
OUT.write(action.strip().replace('"',' '))
或 findall 重新运行失败...
你能帮帮我吗? re.findall 应该在这里工作吗?
我试过 pattern=re.findall("something missing", line) 但它不起作用....
很抱歉问这个问题,但我没能在之前的帖子中找到正确的答案.....
非常感谢!
改变这个,
if pattern in field[1]:
至
if any([True for word in pattern.split() if word in line]):
您可以添加注释,
line+" "+your_annotation
我有一个多行文件,制表符分隔,第二列可能包含(或不包含)一些关键字,
Place1______________fish
Place2______________fishing someting
Placexx_____________something missing
Place_somwhere______something else missing
EHDN_______________fishing something
HDGFE______________looking for something
(线条很难看,但我无法使数据看起来像 table)
每当该行包含 'something missing' 时,我都需要在该行的末尾添加注释,例如“此处需要操作”;
我试过类似的东西:
pattern="something missing"
OUT=open('/Users/user/output.tab','w')
for line in file:
field=line.split('\t')
if pattern in field[1]:
action = ';'.join("ACTION NEEDED")
OUT.write(action.strip().replace('"',' '))
或 findall 重新运行失败...
你能帮帮我吗? re.findall 应该在这里工作吗? 我试过 pattern=re.findall("something missing", line) 但它不起作用.... 很抱歉问这个问题,但我没能在之前的帖子中找到正确的答案..... 非常感谢!
改变这个,
if pattern in field[1]:
至
if any([True for word in pattern.split() if word in line]):
您可以添加注释,
line+" "+your_annotation