国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python中查找excel某一列的重復數據 剔除之后打印

2020-02-23 04:50:17
字體:
來源:轉載
供稿:網友
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]
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海林市| 平山县| 安图县| 濮阳市| 当涂县| 夏河县| 枞阳县| 鹤峰县| 洞头县| 扎囊县| 阿巴嘎旗| 阿克苏市| 阿克| 贵州省| 元江| 东海县| 定安县| 宽甸| 惠州市| 固安县| 宜章县| 论坛| 北海市| 仁寿县| 于田县| 井陉县| 雷波县| 上思县| 永德县| 酉阳| 行唐县| 平南县| 于田县| 巢湖市| 汉阴县| 临漳县| 女性| 靖安县| 慈利县| 溧水县| 夏河县|