脚本专栏 
首页 > 脚本专栏 > 浏览文章

python实现查找excel里某一列重复数据并且剔除后打印的方法

(编辑:jimmy 日期: 2025/6/21 浏览:3 次 )

本文实例讲述了python实现查找excel里某一列重复数据并且剔除后打印的方法。分享给大家供大家参考。具体分析如下:

在python里面excel的简单读写操作我这里推荐使用xlrd(特别是读操作)

import xlrd 
def open_excel(fileName="simple.xls"):
  try:
    fileHandler = xlrd.open_workbook(fileName)
    return fileHandler
  except Exception, e:
    print str(e)  
def scan_excel(sheet_name1=u'Sheet1'):
  handler = open_excel()
  page = handler.sheet_by_name(sheet_name1)
  return page
def trim_cols(index=0):
  page = scan_excel()
  col1 = page.col_values(index)
  col2 = []
  for item in col1:
    if item not in col2:
      col2.append(item)
  print col1
  print col2
def main():
  trim_cols()
if __name__ == "__main__":
  main()  

输出结果:

[1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0]
[1.0, 2.0, 3.0, 4.0]

希望本文所述对大家的Python程序设计有所帮助。

上一篇:Python实现二分查找算法实例
下一篇:Django发送html邮件的方法
一句话新闻
微软与英特尔等合作伙伴联合定义“AI PC”:键盘需配有Copilot物理按键
几个月来,英特尔、微软、AMD和其它厂商都在共同推动“AI PC”的想法,朝着更多的AI功能迈进。在近日,英特尔在台北举行的开发者活动中,也宣布了关于AI PC加速计划、新的PC开发者计划和独立硬件供应商计划。
在此次发布会上,英特尔还发布了全新的全新的酷睿Ultra Meteor Lake NUC开发套件,以及联合微软等合作伙伴联合定义“AI PC”的定义标准。