分享

用python查找excel里面的某一列的重复数据,剔除之后打印

 昵称QAb6ICvc 2013-01-28
用python查找excel里面的某一列的重复数据,剔除之后打印
2012-12-01 10:14:24     我来说两句       作者:androidzhaoxiaogang
收藏    我要投稿
[python] 
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]

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多