[英]python- how to find same words in two different excel workbooks
I want to find the same words in two different excel workbooks. 我想在两个不同的excel工作簿中找到相同的单词。 I have two excel workbooks (data.xls and data1.xls).
我有两个Excel工作簿(data.xls和data1.xls)。 If in data.xls have the same words in the data1.xls, i want it to print the row of data1.xls that contain of the same words with data.xls.
如果data.xls中的data1.xls中有相同的单词,我希望它打印data1.xls中包含与data.xls相同的单词的行。 I hope u can help me.
我希望你能帮助我。 Thank you.
谢谢。
I am assuming that both excel sheets have a list of words, with one word in each cell. 我假设两个excel工作表都有一个单词列表,每个单元格中都有一个单词。
The best way to write this program would be something like this: 编写此程序的最佳方法是这样的:
Open the first excel file, you might find it easier to open if you export it as a CSV first. 打开第一个excel文件,如果先将其导出为CSV文件,可能会发现打开它更容易。
Create a Dictionary to store word and Cell Index Pairs 创建字典以存储单词和单元格索引对
Iterate over each cell/word, add the word to the dictionary as the Key, with the Cell Reference as the Value. 遍历每个单元格/单词,将单词作为键添加到字典中,将“单元格引用”作为值。
Open the second excel file. 打开第二个excel文件。
Iterate over each cell/word, check if the word is present in the Dictionary, if it is, you can print out the corresponding cells or store them however you want. 遍历每个单元格/单词,检查词典中是否存在该单词,如果存在,则可以打印出相应的单元格,也可以根据需要存储它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.