python中查找excel某一列的重复数据 剔除之后打印

yipeiwu_com5年前Python基础
1.在python中excel的简单读写操作,推荐使用xlrd(特别是读操作)

2.到http://pypi.python.org/pypi/xlrd 去下载 xlrd库;

3.工程代码如下:

复制代码 代码如下:

    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+selenium实现京东自动登录及秒杀功能

本文实例为大家分享了selenium+python京东自动登录及秒杀的代码,供大家参考,具体内容如下 运行环境: python 2.7 python安装selenium 安装webdr...

Vue的el-scrollbar实现自定义滚动

Vue的el-scrollbar实现自定义滚动

为什么要用el-scrollbar? 最近在写一个内部平台系统,相信大家都知道,其中会有很多自定义的滚动区域,就比如说现在有一个列表需要滚动,第一个念头就是用 overflow: sc...

Python实现字典去除重复的方法示例

本文实例讲述了Python实现字典去除重复的方法。分享给大家供大家参考,具体如下: #!/usr/bin/env python # encoding: utf-8 #字典去重小代码...

python字典基本操作实例分析

本文实例讲述了python字典基本操作。分享给大家供大家参考。具体如下: d2 = {'spam': 2, 'ham': 1, 'eggs': 3} # make a diction...

Python matplotlib通过plt.scatter画空心圆标记出特定的点方法

Python matplotlib通过plt.scatter画空心圆标记出特定的点方法

在用python画散点图的时候想标记出特定的点,比如在某些点的外围加个空心圆,一样可以通过plt.scatter实现 import matplotlib.pyplot as plt...