我有两个不同的文件File" Sentence"包含一个句子池,请在下面找到快照。 https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo
文件" Word" contians池语,请在下面找到快照。
如果任何单词与句子匹配,我想将单词文件中的单词映射到句子文件,我希望结果以句子和匹配单词的形式
例如: 句子匹配词 Linux和开放堆栈是很棒的Linux Open stack
请在下面找到我的代码,当我尝试将结果提取到csv时,显示错误。
import pandas as pd
import csv
sentence_xlsx = pd.ExcelFile('C:\Python\Seema\Sentence.xlsx')
sentence_all = sentence_xlsx.parse('Sheet1')
#print(sentence_all)
word_xlsx = pd.ExcelFile('C:\Python\Seema\Word.xlsx')
word_all = word_xlsx.parse('Sheet1')
for sentence in sentence_all['Article']:
sentences = sentence.lower()
for word in sentences.split():
if word in ('linux','openstack'):
result = word,sentence
results = open('C:\Python\Seema\result.csv', 'wb')
writer = csv.writer(results, dialect='excel')
writer.writerows(result)
results.close()
Traceback (most recent call last):
File "Word_Finder2.py", line 25, in <module>
results = open('C:\Python\Seema\result.csv', 'wb')
IOError: [Errno 22] invalid mode ('wb') or filename: 'C:\\Python\\Seema\result.c
sv'
答案 0 :(得分:1)
路径的<svg width="300" height="200">
<polygon points="100,10 40,198 190,78 10,78 160,198"
style="fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;" />
</svg>
<svg widht:"100" height:"100">
<path d="M10 10 H 90 V 90 H 10 L 10 10"/>
</svg>
部分将其'\result.csv'
读取为回车符。要解决此问题,请将前导'\r'
附加到路径以使其成为原始字符串文字(credit @georg)。
然后使用r
,所有迭代的结果应该累积到一个列表中,而不仅仅是最后的结果。
writerows