Python 讀取 excel 檔案

2022-09-02 04:57:10 字數 706 閱讀 8982

現在大部分資料都是儲存在excel中或直接調取資料庫,作為剛剛自學python的小白來說怎麼讀取檔案還是比較懵的,現在對python讀取excel檔案進行了一些整理:

#

coding=utf-8

#cmd中進行安裝xlrd庫

pip install xlrd

import

xlrd

#檔案路徑,要用/而不是\

file_path = r'

c:/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檔案

一 安裝xlrd模組 二 使用介紹 1 匯入模組 import xlrd 2 開啟excel檔案讀取資料 data xlrd.open workbook excelfile.xls 3 使用技巧 獲取乙個工作表 table data.sheets 0 通過索引順序獲取 table data.shee...

python讀取excel檔案

coding utf 8 import xlrd 路徑前加 r,讀取的檔案路徑 file path r f test.xlsx 檔案路徑的中文轉碼 file path file path.decode utf 8 獲取資料 data xlrd.open workbook file path 獲取sh...

python讀取excel檔案

週末師姐讓我幫忙處理一下之前的醫療資料,資料都存放在excel檔案中,需要從裡面提取出部分資料並轉化為她指定的格式。總共有20幾個檔案,如果手動處理的話,不僅效率低下而且很繁雜,於是我編寫了python指令碼來完成了本次的工作,下面記錄一下相關的知識,並做乙個總結。我用到的庫是 openpyxl 首...