python獲取excel的一列或者一行的資料

2021-09-14 05:29:01 字數 828 閱讀 6592

用xlrd包

import xlrd

workbook=xlrd.open_workbook('d:\table.xlsx')

sheet=workbook.sheets()[0]

#第b列

sheet.col_values(1)

# 使用下面的方法首先你需要 pandas 包:pip install pandas

importpandas as pd

table=pd.read_excel('d:')

b=table['b']

import xlrd

fname = "d:/x.xlsx"

data = xlrd.open_workbook('d:/x.xlsx')

table = data.sheets()[0] #通過索引順序獲取 

table.row_values(1)

table.col_values(1) 

>>> table.row_values(1)

[1.0, u'', u'']

讀取出來的應該是第乙個sheet中第一行的資料,但excel裡第一行的資料是1 2 3

為什麼會出現這種情況?

我希望獲得某一行或某一列的所有資料

比如說第一行:[1,2,3]

這樣子的

Python獲取excel列表資料

import xlrd import time 設定路徑 file path r c users viruser.v desktop desktop worlddata finds.xlsx utf 8編碼 xlrd.book.encoding utf 8 獲取資料 data xlrd.open w...

python操作excel獲取內容

背景 從excel表中獲取請求url 請求資料 請求型別 預期結果 因此,需要學會如何使用python從excel獲取這些資訊 coding utf 8 import xlrd 建立物件時,獲取對應excel 讀取excel行數 獲取單元格內容 class operationexcel def in...

python 獲取Excel中所有sheets名稱

在這裡不做過多的敘述,用 更為直觀的展示執行過程 第一種方法 獲取檔案的sheep name import pandas as pd sheep name pd.excelfile my.xlsx sheet names sheep name.sheet names print sheet name...