在python中如何将输出映射到csv

2024-10-01 15:44:04 发布

您现在位置:Python中文网/ 问答频道 /正文

这个问题是这个question的后续问题

我也在这里发布了@tobiask的解决方案:

match_region = [map(str, blob.sentences[i-1:i+2])     # from prev to after next
                for i, s in enumerate(blob.sentences) # i is index, e is element
                if search_words & set(s.words)]       # same as your condition

导出匹配区域文件时遇到问题。我想把这个变成一个csv的句子列和每一个结果作为一行。你知道吗


Tags: tofrommapismatchsentences解决方案blob
1条回答
网友
1楼 · 发布于 2024-10-01 15:44:04

这将把匹配区域的内容打印到一个文件中,但是我没有在你的代码上测试它,它也不会打印句子。你知道吗

with open('output.csv', 'w') as f:
    for i, s in enumerate(match_region):
        f.write('"' + i + '","' + s + '"\n')

相关问题 更多 >

    热门问题