Pandas读取表格数据进行处理
import pandas as pd df_policy = pd.read_excel('e:\policy.xlsx') df_sh01 = pd.read_csv('e:\sh01.csv', encoding='gbk') list_not = [] set_found = set() for i in range(df_sh01['目的IP'].__len__()): flag = True for j in range(df_policy['目标地址'].__len__()): if df_sh01['目的IP'][i] in df_policy['目标地址'][j] and str(df_sh01['目的端口'][i]) in df_policy['协议-端口'][j]: flag = False set_found.add(df_policy['ID'][j]) if flag: list_not.append([df_sh01['目的IP'][i], df_sh01['目的端口'][i]]) pd.DataFrame(list_not).to_csv('e:\out.csv') print(list_not.__len__()) print(set_found.__len__(), set_found)