How to read data in excel using Python

高洛峰
Release: 2017-03-17 16:42:12
Original
2317 people have browsed it

python中要想处理excel,必须用到第三方模块xlrd,所以windows 我安装方法是cmd中命令:E:\ANZHUANG\Python\Scripts>easy_install xlrd (路径必须在python的scripts下和必须安装easy_install)

#coding=utf-8 import xlrd def print_xls(path): data=xlrd.open_workbook(path) #打开excel table=data.sheets()[1] #打开excel的第几个sheet nrows=table.nrows #捕获到有效数据的行数 books=[] for i in range(nrows): ss=table.row_values(i) #获取一行的所有值,每一列的值以列表项存在 #print ss for i in range(len(ss)): print ss[i] #输出一行中各个列的值 print '+++++++++++++++++++' if name=='main': print_xls('D:\\文档\\431547909921.xls')
Copy after login

excel内的内容格式如下:

19710208014黄钊医学院预防医学经金学院经济学类

19810208006宋马小薇医学院预防医学医学院临床医学

19910207014杨婵媛医学院制药工程医学院口腔医学

20010207018祖丽皮亚医学院制药工程医学院临床医学

20110207029周力波医学院制药工程医学院临床医学

输出结果:

199.0

10207014.0

杨婵媛

医学院

制药工程

医学院

口腔医学

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

200.0

10207018

祖丽皮亚

医学院

制药工程

医学院

临床医学

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

201.0

10207029

周力波

医学院

制药工程

医学院

临床医学

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


The above is the detailed content of How to read data in excel using Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!