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

yipeiwu_com6年前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循环语句

1、局部变量 for i in range(5): print i, print i, 运行结果: 0 1 2 3 4 4 i是for语句里面的局部变量。但在python...

node.js获取参数的常用方法(总结)

1、req.body 2、req.query 3、req.params 一、req.body例子 body不是nodejs默认提供的,你需要载入body-parser中间件才可以使用re...

Python中使用支持向量机SVM实践

在机器学习领域,支持向量机SVM(Support Vector Machine)是一个有监督的学习模型,通常用来进行模式识别、分类(异常值检测)以及回归分析。 其具有以下特征: &nbs...

Django中多种重定向方法使用详解

前言 本文使用了Django1.8.2 使用场景,例如在表单一中提交数据后,需要返回到另一个指定的页面即可使用重定向方法 一、 使用HttpResponseRedirect fu...

Python内置模块ConfigParser实现配置读写功能的方法

本文实例讲述了Python内置模块ConfigParser实现配置读写功能的方法。分享给大家供大家参考,具体如下: 用于对特定的配置进行操作,当前模块的名称在 python 3.x 版本...