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实现的排列组合、破解密码算法示例

本文实例讲述了Python实现的排列组合、破解密码算法。分享给大家供大家参考,具体如下: 排列组合(破解密码) 1.排列 itertools.permutations(iterabl...

Tensorflow获取张量Tensor的具体维数实例

获取Tensor的维数 >>> import tensorflow as tf >>> tf.__version__ '1.2.0-rc1'...

Python cookbook(数据结构与算法)实现查找两个字典相同点的方法

Python cookbook(数据结构与算法)实现查找两个字典相同点的方法

本文实例讲述了Python实现查找两个字典相同点的方法。分享给大家供大家参考,具体如下: 问题:寻找两个字典中间相同的地方(相同的键、相同的值等) 解决方案:通过keys()或者item...

解决python3在anaconda下安装caffe失败的问题

Python 跟 Python3 完全就是两种语言 1、 import caffe FAILED  环境为 Ubuntu 16 cuda 8.0 NVIDIA 361.77...

Python自动化运维和部署项目工具Fabric使用实例

Fabric 是使用 Python 开发的一个自动化运维和部署项目的一个好工具,可以通过 SSH 的方式与远程服务器进行自动化交互,例如将本地文件传到服务器,在服务器上执行shell 命...