Python 如何读取.csv文件的单个列? 20
2个回答
展开全部
import xlrd
EXCEL_BOOK_FULLNAME='FULL FILE NAME'
workbook=xlrd.open_workbook(EXCEL_BOOK_FULLNAME)
worksheet=workbook.sheet_by_name('Sheet1')
rows=worksheet.nrows #worksheet rows
cols=worksheet.ncols #worksheet columns
lists=[[],[],[],[]] #modify this according your column counts
for c in range(cols): #transfer excel values into lists
for r in range(rows):
lists[c].append(worksheet.cell_value(r,c))
EXCEL_BOOK_FULLNAME='FULL FILE NAME'
workbook=xlrd.open_workbook(EXCEL_BOOK_FULLNAME)
worksheet=workbook.sheet_by_name('Sheet1')
rows=worksheet.nrows #worksheet rows
cols=worksheet.ncols #worksheet columns
lists=[[],[],[],[]] #modify this according your column counts
for c in range(cols): #transfer excel values into lists
for r in range(rows):
lists[c].append(worksheet.cell_value(r,c))
追问
请问导入xlrd需要加入什么包吗?
workbook=xlrd.open_workbook(EXCEL_BOOK_FULLNAME)
这句话运行不了
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询