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]

相关文章

在Django框架中伪造捕捉到的URLconf值的方法

比如说你有匹配某个模式的一堆视图,以及一个并不匹配这个模式但视图逻辑是一样的URL。 这种情况下,你可以通过向同一个视图传递额外URLconf参数来伪造URL值的捕捉。 例如,你可能有一...

python银行系统实现源码

本文实例为大家分享了python实现银行系统的具体代码,供大家参考,具体内容如下 1、admin.py 定义管理员信息和主界面显示 #!/usr/bin/env python # c...

Pycharm设置utf-8自动显示方法

如下所示: File->Setting->Editor->File and Code Templates->python script,右侧框框内输入: ...

python pyinstaller 加载ui路径方法

如下所示: class Login(QMainWindow): """登录窗口""" global status_s global connect_signal de...

Python获取指定文件夹下的文件名的方法

本文采用os.walk()和os.listdir()两种方法,获取指定文件夹下的文件名。 一、os.walk() 模块os中的walk()函数可以遍历文件夹下所有的文件。 os.wa...