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

yipeiwu_com6年前Python基础

本文实例讲述了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的unittest架构公共参数token提取方法详解

额。。。每个请求都有token值的传入,但是token非常易变,一旦变化,所有的接口用例都得改一遍token,工作量太大了。。。 那么有没有一种方法能把token提取出来,作为一个全局变...

Python : turtle色彩控制实例详解

turtle.pencolor(* args ) 返回或设置pencolor。 允许四种输入格式: pencolor() 将当前的pencolor返回为颜色规范字符串或元组(...

python实现Flappy Bird源码

python实现Flappy Bird源码

Flappy Bird是前段时间(好像一年or两年前....)特别火的有一个小游戏,相信大家都玩过。 Flappy Bird操作简单,通过点击手机屏幕使Bird上升,穿过柱状障碍物之后得...

Python实现正弦信号的时域波形和频谱图示例【基于matplotlib】

Python实现正弦信号的时域波形和频谱图示例【基于matplotlib】

本文实例讲述了Python实现正弦信号的时域波形和频谱图。分享给大家供大家参考,具体如下: # -*- coding: utf-8 -*- # 正弦信号的时域波形与频谱图 impor...

Python流程控制 while循环实现解析

Python流程控制 while循环实现解析

一、语法 while 条件: 执行代码 while就是当的意思,它指当其后面的条件成立,就执行while下面的代码。 例:写一个从0打印到10的程序 count = 0 whi...