使用Python对Excel内地址进行对比

python——Excel地址对比
代码如下

# coding:utf-8
'Ybt对比两个Excel中地址并输出到桌面txt'
import pandas as pd

df = pd.read_excel(r'C:\Users\ybt\Desktop\date.xls',
                   sheet_name="bt", usecols=[0],
                   skiprows=1)

df1 = pd.read_excel(r'E:\86桌面地址\86\通信云账号-页面-主机-承载网-数据库信息合集(1)(1).xlsx',
                    sheet_name='省端地址表',
                    usecols=[0, 3, 4], nrows=178,
                    skiprows=[0, 1, 2, 3, 4, 8])

with (open(r'C:\Users\ybt\Desktop\ls.txt', 'w+')) as k:
    for i in 2, 3:  # 循环对应地址列
        for r in df.itertuples():  # 对索引和列进行遍历
            for rr in df1.itertuples():
                if str(r[1]) in str(rr[i]).split('\n'):
                    if '\n' in str(rr[i]):
                        # 去除单个单元格两个地址回车
                        k.write('%s\t\t%s\t\t%s' % (rr[1], r[1],
                                                    str(rr[i]).replace('\n', '\t')) + '\n')
                    else:
                        k.write('%s\t\t%s\t\t%s' % (rr[1], r[1], rr[i]) + '\n')
posted @ 2022-10-08 10:41  ybt&kexiao  阅读(70)  评论(0编辑  收藏  举报