This article describes a Python implementation that looks for duplicate data in Excel and prints it out after it is removed. Share to everyone for your reference. The specific analysis is as follows:
In Python, Excel's simple read and write operation I recommend using XLRD (especially read operation)
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23-24 |
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_na Me (sheet_name1) return page def trim_cols (index=0): page = Scan_excel () col1 = page.col_values (index) col2 = [] for item I N col1:if Item not in Col2:col2.append (item) Print col1 print col2 def main (): Trim_cols () if __name__ = = "__main__": MA In () |
Output results:
?
1 2 |
[1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0] [1.0, 2.0, 3.0, 4.0] |
I hope this article will help you with your Python programming.