1. 程式人生 > >Python 讀取 excel 文件

Python 讀取 excel 文件

user top 讀取 value odi excel文件 utf mil 獲取

現在大部分數據都是存儲在excel中或直接調取數據庫,作為剛剛自學Python的小白來說怎麽讀取文件還是比較懵的,現在對Python讀取excel文件進行了一些整理:

#coding=utf-8
#cmd中進行安裝xlrd庫
pip install xlrd
import xlrd
#文件路徑,要用/而不是\
file_path = rC:/Users/mingli.zhao/Desktop/七天.xlsx
#中文轉碼
#file_path = file_path.decode(‘utf-8‘)
#獲取數據
data = xlrd.open_workbook(file_path)
#獲取sheet
table = data.sheet_by_name(Sheet1) #獲取總行數 nrows = table.nrows #獲取總列數 ncols = table.ncols #獲取第一行的數值 table.row_values(1) #獲取第一列的數值 table.col_values(1) #獲取第二行第一列單元格的數值 cell_value = table.cell(1,0).value

Python 讀取 excel 文件