Print _python after data de-duplication in Python looking for a column in Excel

Source: Internet
Author: User
Tags in python
1. Excel in Python simple read and write operation, recommend the use of XLRD (especially read operation)

2. Go to http://pypi.python.org/pypi/xlrd to download XLRD library;

3. The engineering code is as follows:

Copy Code code as follows:

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 ()


Print results:
[1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0]
[1.0, 2.0, 3.0, 4.0]
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.