看板 Python 關於我們 聯絡資訊
上網爬文說要載入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://www.ptt.cc/bbs/Python/M.1479542024.A.5A8.html
sky800507: 沒用過這個套件,不過要開excel用pandas就好了!? 11/19 20:09
sky800507: import pandas as pd 11/19 20:12
sky800507: pd.read_excel() 11/19 20:12
s860134: open_workbook 有個 encoding_override 參數,調一下吧 11/20 00:15
oliversu1211: sky800507 pandas套件安裝好像有點困難 安裝幾次都 11/20 12:46
oliversu1211: 不成功 11/20 12:46
sky800507: 直接裝anaconda 比較容易,內含pandas套件 11/20 13:58
s860134: 就單純的編碼問題 11/20 15:49
oliversu1211: s860134 那請問xlrd可以做像excel sumif函數那樣嗎 11/20 17:11
oliversu1211: ?還是需要另外載套件? 11/20 17:11
oliversu1211: sky800507 有了~是網頁模式對吧? 11/20 17:11
s860134: 你可能有甚麼誤會,xlrd 就是只是拿來做讀取excel 的功能 11/20 17:21
s860134: pandas 也只是包一包把讀取功能包起來而已 11/20 17:21
s860134: 你問可以做 sumif 這根讀取沒關係,應該是你自己寫啊’ 11/20 17:22
oliversu1211: s860134 那是我誤會了,因為我上網查用python寫sumi 11/20 18:46
oliversu1211: f,出現的結果都跟pandas有關,我以為套件裡面除了 11/20 18:46
oliversu1211: 有載入檔案,還會附帶其他功能 11/20 18:46
Muhaosic: 可是PANDAS有辦法在讀取excel後選擇你要的範圍嗎~? 11/21 10:34
oliversu1211: Muhaosic 他是用group by的方式,然後我搞不清楚pan 11/21 19:02
oliversu1211: das要怎麼選擇工作表,所以就讓他只有ㄧ張工做表, 11/21 19:02
oliversu1211: 目前只研究到這裡 11/21 19:02