python文件读写总结

0. python 读取excel__author__ = 'HM'#Use the excellent xlrd package, which works on any platform. That means you can read Excel files from Python in Linux! Example usage:#Open the workbookimport
摘要由CSDN通过智能技术生成

0. python 读取excel

__author__ = 'HM'
#Use the excellent xlrd package, which works on any platform. That means you can read Excel files from Python in Linux! Example usage:

#Open the workbook

import xlrd
wb = xlrd.open_workbook('myworkbook.xls')
#Check the sheet names

wb.sheet_names()
#Get the first sheet either by index or by name

sh = wb.sheet_by_index(0)
sh = wb.sheet_by_name(u'Sheet1')
#Iterate through rows, returning each as a list that you can index:

for rownum in range(sh.nrows):
    print sh.row_values(rownum)
#If you just want the first column:

first_column = sh.col_values(0)
#Index individual cells:

cell_A1 = sh.cell(0,0).value
cell_C4 = sh.cell(rowx=3,colx=2).value
#(Note Python indices start at zero but Excel starts at one)

#Turns out the put_cell() method isn’t supported, so ignore the following section (Thanks for the heads up, John!)

#Put something in th
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值