python擷取excel資料

來源:互聯網
上載者:User

標籤:mes   script   差集   [1]   val   exce   col   []   remove   

#!/usr/bin/python# --*-- coding: utf-8 --*--import xlrdexcel_file = "/data/script/cmdb_excel_2018_08_04_16_03.xlsx"csv_file = "/data/script/jms.xlsx"#################get old jms ip_list ####################workbook = xlrd.open_workbook(excel_file)sheet_name_list = workbook.sheet_names()ip_list = []#ip_cols = sheet1.col_values(1)#print(ip_cols[1])for i in range(0,4):sheet = workbook.sheet_by_index(i)ip_cols = sheet.col_values(1)ip_list.extend(ip_cols)ip_list.remove('IP')ip_list.remove('IP')ip_list.remove('IP')ip_list.remove('IP')#print(len(ip_list))#for a in ip_list:#if ip_list.count(a) > 1:#print a#########################get new jms ip_list #############workbook_new = xlrd.open_workbook(csv_file)new_sheet_name_list = workbook_new.sheet_names()new_ip_list = []#ip_cols = sheet1.col_values(1)#print(ip_cols[1])new_sheet = workbook_new.sheet_by_index(0)new_ip_cols = new_sheet.col_values(0)new_ip_list.extend(new_ip_cols)#new_ip_list.remove('IP')#print(new_ip_list)#print(len(new_ip_list))#######################################################################比較ip_list和new_ip_list的差集##########res = set(ip_list).difference(set(new_ip_list))print(len(res))for i in res:print(i)


python擷取excel資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.