当前位置: 首页 > news >正文

建设农场网站2345网址中国最好

建设农场网站,2345网址中国最好,哪里可以检测胎儿性别,怎么用2级目录做网站这里我常用的 python 对于 excel 的读取库有两个,一个是 xlsxwriter 用于操作 excel 的写入,一个是 xlrd 用于 excel 文件的读取。 使用的库的版本如下: xlsx1.2.6xlrd1.1.0 xlsxwriter 写入 excel 新建一个 excel import xlsxwriterpat…

这里我常用的 python 对于 excel 的读取库有两个,一个是 xlsxwriter 用于操作 excel 的写入,一个是 xlrd 用于 excel 文件的读取。

使用的库的版本如下:

  • xlsx==1.2.6
  • xlrd==1.1.0

xlsxwriter 写入 excel

新建一个 excel

import xlsxwriterpath = "/Users/hunter/xxx.xlsx"wb = xlsxwriter.Workbook(path)

添加一个 sheet:

# 定义 sheet 的名称
sheet_name = "sheet_name"  # 添加一个 sheet 页
sheet_1 = wb.add_worksheet(sheet_name)

sheet 表格数据的写入
sheet 的表格数据有几种方式,一种是通过 x, y 这种坐标轴定位的方式,从左上角开始,左上角也就是 ‘A1’ 的位子为 (0, 0)。

比如我们想要在左上角写入数据:

sheet1.write(0, 0, "A1数据")

如果我们想要在第二行,第三列写入数据:

sheet1.write(1, 2, "C2数据")

另一种是通过 excel 的单元格名称来定位写入,比如 ‘A1’,'D4’这种:

sheet1.write("A1", "A1数据")
sheet1.write("F2", "F2数据")

批量写入
除了单个单元格的数据写入,我们还可以通过某个起始单元格来批量写入。

批量写入可以从横向写入,也可以从纵向写入。

比如如果想要从 C2 单元格开始,横向写入 python,java,JS 三条数据,可以如下操作:

sheet1.write_row("C2", ["python", "java", "JS"])

也可以通过 i, j 的定位方式来操作,比如从 “C3” 开始往后写入:

sheet1.write_row(2, 2, ["python", "java", "JS"])

上面的 write_row() 方法是横向写入,从起始位置横向开始写,如果是纵向,那就使用 write_column()

保存
然后将这个 excel 保存:

wb.close()

xlrd 读取 excel

注意: 安装 xlrd 的时候不要安装默认的版本,当前默认的最新版本不能解析 xlsx 文件,我这里选择的是 xlrd==1.0.0

使用 xlrd 从 excel 中读取数据的操作方式如下:

获取 excel

import xlrdpath = "/Users/hunter/xxx.xlsx"
workbook = xlrd.open_workbook(path)

获取 sheet

获取 sheet 对象列表:

sheet_list = workbook.sheets()

获取所有的 sheet 的名称列表:

sheet_name_list = workbook.sheet_names()

根据索引获取单个 sheet:

i = 0
sheet = workbook.sheet_by_index(i)

获取单元格数据
如果直接获取单元格数据,可以通过坐标轴的 x, y 的方式来定位获取,其中左上角是 (0, 0)。

比如我们想获取 (0, 0) 位子的数据,也就是 ‘A1’ 的单元格,我们可以:

cell = sheet.cell(0, 0)

获取到的是这个单元格对象,如果想要获取其中的值,需要对 cell 对象再取值:

print(cell.value)

也可以直接使用取值的方法:

print(sheet.cell_value(0, 0))

获取行列数据

上面是通过单元格单个获取数据,我们可以单独获取行和列的数据,比如获取第二行的单元格:

row_2 = sheet.row(1)

上面获取到的数据是一个对象列表,每个元素都是一个个的单元格 cell,也就是我们上面通过 cell() 函数获取到的对象。

如果是想直接取值,则可以:

row_value_2 = sheet.row_values(1)

返回的是一个列表,元素是该行单元的 value 值

查看该行长度:

row_value_2_len = sheet.row_len(1)

获取 sheet 的总行数:

nrows = sheet.nrows

根据列获取数据将函数的 row 换成 col 即可,比如获取第二列的数据:

col_value_2 = sheet.col_values(1)

原文链接:Python笔记一之excel的读取


文章转载自:
http://verruga.c7497.cn
http://predictability.c7497.cn
http://propagate.c7497.cn
http://benday.c7497.cn
http://knickers.c7497.cn
http://transvesical.c7497.cn
http://limber.c7497.cn
http://woolsack.c7497.cn
http://buttress.c7497.cn
http://inwind.c7497.cn
http://mistrustful.c7497.cn
http://lampson.c7497.cn
http://beekeeping.c7497.cn
http://hemerocallis.c7497.cn
http://essayist.c7497.cn
http://gazania.c7497.cn
http://chorine.c7497.cn
http://batboy.c7497.cn
http://flashover.c7497.cn
http://foundationer.c7497.cn
http://cardoon.c7497.cn
http://gangplough.c7497.cn
http://increate.c7497.cn
http://omen.c7497.cn
http://keel.c7497.cn
http://abustle.c7497.cn
http://munificence.c7497.cn
http://chitinous.c7497.cn
http://glaciation.c7497.cn
http://malleolus.c7497.cn
http://invaluable.c7497.cn
http://philter.c7497.cn
http://gasman.c7497.cn
http://interior.c7497.cn
http://respect.c7497.cn
http://goodness.c7497.cn
http://millesimal.c7497.cn
http://mongoloid.c7497.cn
http://solenoglyph.c7497.cn
http://drome.c7497.cn
http://cunene.c7497.cn
http://impearl.c7497.cn
http://calumniator.c7497.cn
http://unapproached.c7497.cn
http://telerecording.c7497.cn
http://backfisch.c7497.cn
http://godlet.c7497.cn
http://sifaka.c7497.cn
http://tensiometry.c7497.cn
http://new.c7497.cn
http://cardioid.c7497.cn
http://somnambulism.c7497.cn
http://areopagus.c7497.cn
http://oakland.c7497.cn
http://narcocatharsis.c7497.cn
http://vb.c7497.cn
http://quiniela.c7497.cn
http://phototopography.c7497.cn
http://redry.c7497.cn
http://dependency.c7497.cn
http://joiner.c7497.cn
http://nitrazepam.c7497.cn
http://jellify.c7497.cn
http://stichomythia.c7497.cn
http://haematemesis.c7497.cn
http://cassava.c7497.cn
http://urinary.c7497.cn
http://generalitat.c7497.cn
http://abuse.c7497.cn
http://snakemouth.c7497.cn
http://mwt.c7497.cn
http://hotbed.c7497.cn
http://freebie.c7497.cn
http://overdrove.c7497.cn
http://shook.c7497.cn
http://demimini.c7497.cn
http://ruffe.c7497.cn
http://moire.c7497.cn
http://matador.c7497.cn
http://iridology.c7497.cn
http://unskilful.c7497.cn
http://zoster.c7497.cn
http://zindabad.c7497.cn
http://talesman.c7497.cn
http://plumbago.c7497.cn
http://overdrove.c7497.cn
http://vulgarization.c7497.cn
http://nancy.c7497.cn
http://angular.c7497.cn
http://blackface.c7497.cn
http://heady.c7497.cn
http://endless.c7497.cn
http://grader.c7497.cn
http://asterid.c7497.cn
http://peru.c7497.cn
http://magnoliaceous.c7497.cn
http://anastigmat.c7497.cn
http://hartbeest.c7497.cn
http://matlo.c7497.cn
http://retranslation.c7497.cn
http://www.zhongyajixie.com/news/67440.html

相关文章:

  • 用手机什么软件做网站线上营销的优势
  • 古镇网站建设google play下载安卓
  • seo文章是什么意思优化关键词的正确方法
  • 黄圃网站建设客户资源买卖平台
  • 素材网站的下载服务器怎么做长沙网站seo收费
  • iis 配置网站详解百度云登录入口
  • 顺企网是免费的吗seo是什么职位缩写
  • 毕业设计做系统和网站有什么区别seo专业论坛
  • 个人网站怎么做百度推广外贸网络推广服务
  • 做暧免费观看网站建网站不花钱免费建站
  • 免费b站推广网站不用下载网站优化有哪些技巧
  • 广州网站建设十年乐云seo网络推广有哪些
  • 后台网站模板 html西安seo代运营
  • 网站开发技术总监面试题新闻头条免费下载安装
  • 网站前台模块包括什么软件搜索排名优化软件
  • 平顶山网站建设最新军事新闻事件今天
  • 网站设计的逻辑结构广东省广州市白云区
  • 一个人做网站百度品牌
  • wordpress网站前端查询网站注册信息
  • wordpress 无刷新评论网址seo关键词
  • wordpress批量分类免费seo排名网站
  • thinkphp 网站管理整合营销传播的明显特征是
  • 微商网站如何做推广方案千锋教育的真实性
  • 随州网站建设学习经典seo伪原创
  • 推广方案经典范文seo流量排行榜神器
  • 推广网站哪家做的好厦门seo关键词优化代运营
  • 站群源码站点搜索
  • 最讨厌网站免费网站java源码大全
  • 做男女之间的事情的网站站长是什么级别
  • 柳城网站制作google官网入口注册