![](/img/trans.png)
[英]Is there any way in which we can add data in file using python in increment order
[英]Is there any way in which we can compare the values from a column in excel file with the contents of text files using Python?
我試圖檢查我們是否可以將 excel 文件單列中存在的值與文本文件中的值進行比較,如果 excel 文件的單詞與文本文件中的單詞匹配,我們必須打印匹配的單詞。 前任:-
我有一個 excel 表,其中 A 列有球員的姓名:-
第 1 欄:-
播放器 1 播放器 2 播放器 3 。 . . . 玩家N
.Txt 文件 - 包含對運動及其傳奇的描述,超過 300 字。
這個想法是查找第 1 列中的任何單詞是否與文本文件中的單詞匹配,如果是這種情況,我們希望在字典中打印匹配的單詞。
期待新的想法。
感謝團隊。
player.xlsx 包含一列
player.txt 包含
Player 2 bla bla
meh meh Player 5
import pandas as pd
input_xlsx = 'players.xlsx'
input_txt = 'players.txt'
players = pd.read_excel(input_xlsx,header=None)[0].to_list()
with open(input_txt,'r') as f:
text = ''.join(f.readlines())
for player in players:
if player in text:
print(player)
輸出是
Player 2
Player 5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.