This article mainly introduces how to use python to find a column of duplicate data in an excel file and print the data after removal. It involves the skills related to using the xlrd module to Operate Excel in Python, for more information about how to use python to find and print duplicate data in a column in an excel file, see the example in this article. 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)
Import xlrd def open_excel (fileName = "simple.xls"): try: fileHandler = xlrd. open_workbook (fileName) return fileHandler handle T Exception, e: print str (e) def scan_excel (sheet_name1 = u 'sheet1'): handler = open_excel () page = handler. sheet_by_name (sheet_name1) return pagedef 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 col2def main (): trim_cols () if _ name _ = "_ main _": main ()
Output result:
[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.