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

时间:2022-10-27 06:34:00 

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]

标签:excel,重复数据
0
投稿

猜你喜欢

  • MySQL数据库常见的出错代码及出错信息

    2008-05-27 12:29:00
  • 解决GD中文乱码问题

    2024-06-07 15:46:19
  • pytorch 多个反向传播操作

    2021-03-05 02:21:49
  • 在MySQL中删除表的操作教程

    2024-01-15 09:37:46
  • python绘制棉棒图的方法详解

    2021-11-06 06:24:58
  • Scrapy爬虫实例讲解_校花网

    2023-03-02 14:46:39
  • HTML5的革新:结构之美

    2011-04-16 10:57:00
  • pytorch之torchvision.transforms图像变换实例

    2021-05-19 05:44:05
  • 查看Django和flask版本的方法

    2021-01-29 02:50:11
  • 仿QQ和MSN消息提示的效果代码

    2010-03-16 12:17:00
  • Python使用Pickle模块进行数据保存和读取的讲解

    2021-08-23 19:37:55
  • python-opencv在有噪音的情况下提取图像的轮廓实例

    2023-01-10 08:48:36
  • php正则过滤html标签、空格、换行符的代码(附说明)

    2023-07-22 07:58:01
  • Go基础教程系列之import导入包(远程包)和变量初始化详解

    2024-02-22 03:33:53
  • JavaScript给数组添加元素的6个方法

    2024-04-30 08:46:47
  • PHP PDOStatement::getColumnMeta讲解

    2023-06-22 08:34:14
  • Python利用Selenium实现网站自动签到功能

    2021-04-22 18:20:02
  • MYSQL分页limit速度太慢的优化方法

    2024-01-15 21:38:42
  • ASP连接Oracle数据库的例子

    2007-10-02 12:44:00
  • python之cur.fetchall与cur.fetchone提取数据并统计处理操作

    2023-11-30 05:34:06
  • asp之家 网络编程 m.aspxhome.com