Python: Find a column of duplicate data in an excel file and print it after elimination
This example describes how to use python to find and print a column of duplicate data in an excel file. Share it with you for your reference. The specific analysis is as follows:
In python, I recommend using xlrd (especially read Operations) for simple excel read/write operations)
?
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 t 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 () |
Output result:
?
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 Python programming.