Read data from excel in Python

Source: Internet
Author: User
In Python to work with Excel, you must use the third-party module XLRD, so the Windows I install method is cmd command: E:\anzhuang\python\scripts>easy_install xlrd (The path must be under Python's scripts and must be installed Easy_install)

#coding =utf-8import xlrddef Print_xls (path):d ata=xlrd.open_workbook (path)   #打开exceltable =data.sheets () [1] # Opening the first sheetnrows=table.nrows of Excel   #捕获到有效数据的行数books =[]for i in Range (nrows): Ss=table.row_values (i)   # Gets all the values of a row, the value of each column exists as a list item #print ssfor i in range (len (ss)):p rint ss[i]            #输出一行中各个列的值print ' +++++++++++++++++++ ' if __name_ _== ' __main__ ':p rint_xls (' d:\\ document \\431547909921.xls ')

The content format in Excel is as follows:

19710208014 Huang College of Preventive Medicine, School of Economics

19810208006 the clinical medicine of the School of Preventive Medicine, song Ma Xiaowei female Medical College

19910207014 Yang Yanyuan Medical College of Pharmacy, pharmaceutical engineering, stomatology

20010207018 Clinical Medicine of Pharmaceutical Engineering Medical College, Zuli

20,110,207,029 Zhou Li Bo Male Medical College Pharmaceutical Engineering Medical School clinical Medicine

Output Result:

199.0

10207014.0

Yang Yanyuan

Woman

Medical

Pharmaceutical Engineering

Medical

Oral medicine

+++++++++++++++++++

200.0

10207018

Zulpiye

Woman

Medical

Pharmaceutical Engineering

Medical

Clinical

+++++++++++++++++++

201.0

10207029

Zhou Lipo

Man

Medical

Pharmaceutical Engineering

Medical

Clinical

+++++++++++++++++++

  • 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.