作者oliversu1211 (oliversu)
看板Python
标题[问题] python载入excel
时间Sat Nov 19 15:53:41 2016
上网爬文说要载入xlrd套件
载入套件之後,开始要载入excel时程式码出现一些问题
想请高人指点一下,小弟我感激不尽
---以下是我的程式码---
import xlrd
data = xlrd.open_workbook('B18.xlsx')
table = data.sheets()[0]
nrows = table.nrows
ncols = table.ncols
colnames = table.row_values(colnameindex)
list =[]
for rownum in range(1,nrows):
row = table.row_values(rownum)
if row:
app = {}
for i in range(len(colnames)):
app[colnames[i]] = row[i]
list.append(app)
return list
--以下是我执行.py档时出现的错误--
http://imgur.com/a/OEpEr
初学python请大家多多指教
也请大家鞭小力一点
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 114.34.109.96
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1479542024.A.5A8.html
1F:推 sky800507: 没用过这个套件,不过要开excel用pandas就好了!? 11/19 20:09
2F:→ sky800507: import pandas as pd 11/19 20:12
3F:→ sky800507: pd.read_excel() 11/19 20:12
4F:→ s860134: open_workbook 有个 encoding_override 参数,调一下吧 11/20 00:15
5F:→ oliversu1211: sky800507 pandas套件安装好像有点困难 安装几次都 11/20 12:46
6F:→ oliversu1211: 不成功 11/20 12:46
7F:推 sky800507: 直接装anaconda 比较容易,内含pandas套件 11/20 13:58
8F:→ s860134: 就单纯的编码问题 11/20 15:49
9F:→ oliversu1211: s860134 那请问xlrd可以做像excel sumif函数那样吗 11/20 17:11
10F:→ oliversu1211: ?还是需要另外载套件? 11/20 17:11
11F:→ oliversu1211: sky800507 有了~是网页模式对吧? 11/20 17:11
12F:→ s860134: 你可能有甚麽误会,xlrd 就是只是拿来做读取excel 的功能 11/20 17:21
13F:→ s860134: pandas 也只是包一包把读取功能包起来而已 11/20 17:21
14F:→ s860134: 你问可以做 sumif 这根读取没关系,应该是你自己写啊’ 11/20 17:22
15F:→ oliversu1211: s860134 那是我误会了,因为我上网查用python写sumi 11/20 18:46
16F:→ oliversu1211: f,出现的结果都跟pandas有关,我以为套件里面除了 11/20 18:46
17F:→ oliversu1211: 有载入档案,还会附带其他功能 11/20 18:46
18F:→ Muhaosic: 可是PANDAS有办法在读取excel後选择你要的范围吗~? 11/21 10:34
19F:→ oliversu1211: Muhaosic 他是用group by的方式,然後我搞不清楚pan 11/21 19:02
20F:→ oliversu1211: das要怎麽选择工作表,所以就让他只有ㄧ张工做表, 11/21 19:02
21F:→ oliversu1211: 目前只研究到这里 11/21 19:02