python 读取行数据_openpyxl读取所有行数据之rows属性
openpyxl读取一个sheet的所有行数据可以用rows属性,官方文档如下:
If you need to iterate through all the rows or columns of a file, you can instead use the Worksheet.rows property:
sheet的rows属性返回的是一个生成器,如下:
# -*- coding: utf-8 -*-
from openpyxl import load_workbook
wb = load_workbook('test.xlsx',data_only=True)
for sheet in wb:
sheet_name = sheet.title
data_all = sheet.rows
print('sheet名:',sheet_name)
print(data_all)
sheet名: 北京
sheet名: 上海
sheet名: 杭州
可以直接遍历生成器也可以使用tuple将生成器变为元组来输出行:
# -*- coding: utf-8 -*-
from openpyxl import load_workbook
wb = load_workbook('test.xlsx',data_only=True)
for sheet in wb:
sheet_name = sheet.title
data_all = sheet.rows
print('sheet名:',sheet_name)
data_tuple = tuple(data_all)
for row in data_tuple:
print(row)
sheet名: 北京
(, )
(, )
(, )
(, )
(, )
(, )
(, )
sheet名: 上海
(, )
(, )
(, )
(, )
(, )
(, )
(, )
(, )
(, )
(, )
(, )
sheet名: 杭州
(, )
(, )
(, )
(, )
(, )
(, )
(, )
(, )
(, )
(, )
(, )
输出元格的数据,需要value属性:
# -*- coding: utf-8 -*-
from openpyxl import load_workbook
wb = load_workbook('test.xlsx',data_only=True)
for sheet in wb:
sheet_name = sheet.title
data_all = sheet.rows
print('sheet名:',sheet_name)
data_tuple = tuple(data_all)
for row in data_tuple:
print('===一行数据如下===:')
for cell in row:
value = cell.value
print(value)
sheet名: 北京
===一行数据如下===:
贡院6号
https://bj.5i5j.com/xiaoqu/117460.html
===一行数据如下===:
万年花城二期
https://bj.5i5j.com/xiaoqu/369118.html
===一行数据如下===:
铁医新楼
https://bj.5i5j.com/xiaoqu/428075.html
===一行数据如下===:
百万庄大街乙21号楼
https://bj.5i5j.com/xiaoqu/14042.html
===一行数据如下===:
观澳园
https://bj.5i5j.com/xiaoqu/3464.html
===一行数据如下===:
天鹅湾南区
https://bj.5i5j.com/xiaoqu/10522.html
===一行数据如下===:
报国寺1号院
https://bj.5i5j.com/xiaoqu/6250.html
sheet名: 上海
===一行数据如下===:
静安豪景苑
https://sh.5i5j.com/xiaoqu/79364.html
===一行数据如下===:
新泾苑
https://sh.5i5j.com/xiaoqu/138741.html
===一行数据如下===:
兆嘉苑
https://sh.5i5j.com/xiaoqu/367631.html
===一行数据如下===:
天山怡景苑
https://sh.5i5j.com/xiaoqu/385850.html
===一行数据如下===:
金星绿苑
https://sh.5i5j.com/xiaoqu/390212.html
===一行数据如下===:
申晖小区
https://sh.5i5j.com/xiaoqu/436536.html
===一行数据如下===:
共康四村
https://sh.5i5j.com/xiaoqu/197400.html
===一行数据如下===:
崧泽华城青湖苑
https://sh.5i5j.com/xiaoqu/377290.html
===一行数据如下===:
新昌里公寓
https://sh.5i5j.com/xiaoqu/47394.html
===一行数据如下===:
建国西路158弄
https://sh.5i5j.com/xiaoqu/125420.html
===一行数据如下===:
蔷薇七村
https://sh.5i5j.com/xiaoqu/388767.html
sheet名: 杭州
===一行数据如下===:
复兴城市家园
https://hz.5i5j.com/xiaoqu/100000000001038.html
===一行数据如下===:
木材新村
https://hz.5i5j.com/xiaoqu/100000000004309.html
===一行数据如下===:
万寿亭街
https://hz.5i5j.com/xiaoqu/100000000002688.html
===一行数据如下===:
瓶窑镇凤溪路
https://hz.5i5j.com/xiaoqu/100000000000367.html
===一行数据如下===:
孝子坊
https://hz.5i5j.com/xiaoqu/100000000002902.html
===一行数据如下===:
永和坊
https://hz.5i5j.com/xiaoqu/100000000002147.html
===一行数据如下===:
教工路131号
https://hz.5i5j.com/xiaoqu/100000000001423.html
===一行数据如下===:
星星港湾琴海居
https://hz.5i5j.com/xiaoqu/100000000005718.html
===一行数据如下===:
文二路98号
https://hz.5i5j.com/xiaoqu/100000000001269.html
===一行数据如下===:
龙悦湾
https://hz.5i5j.com/xiaoqu/100000000006161.html
===一行数据如下===:
意盛花苑
https://hz.5i5j.com/xiaoqu/100000000002797.html
python 读取行数据_openpyxl读取所有行数据之rows属性相关推荐
- python某行某列读取数据_使用scrpython从某行的第一列提取数据
在您的情况下,解决方案是:td:nth-child(1) Selects every element that is the first child of its parent >>> ...
- python 按照行取平均值补齐缺失数据
import pandas as pd###根据行来求平均值 def fill_NAN():filePath = r'E:\study-python\0819\filled_meter-500.csv ...
- python读文件和写文件-python开发--从文件中读取数据和写入文件
#! /usr/bin/env python -*- coding:utf-8 -*- """ @Author:gcan @Email:1528667112@qq.com ...
- python导入txt为dataframe-python读取文本中数据并转化为DataFrame的实例
在技术问答中看到一个这样的问题,感觉相对比较常见,就单开一篇文章写下来. 从纯文本格式文件 "file_in"中读取数据,格式如下: 需要输出成"file_out&quo ...
- 【Python】从文件中读取数据
从文件中读取数据 1.1 读取整个文件 要读取文件,需要一个包含几行文本的文件(文件PI_DESC.txt与file_reader.py在同一目录下) PI_DESC.txt 3.1415926535 ...
- 【python图像处理】txt文件数据的读取与写入
在使用python进行数据和图像处理的过程中,经常会遇到从txt文件中读取数据.已经将处理过程中的矩阵数据写入到txt文件的情形,如在伪彩映射中读取颜色映射表. 下面介绍几种我平时常用的txt文件数据 ...
- python读取html文件中的表格数据_Python 读取各类文件格式的文本信息 | doc,excel,html,mht...
原标题:Python 读取各类文件格式的文本信息 | doc,excel,html,mht 众所周知,python最强大的地方在于,python社区汇总拥有丰富的第三方库,开源的特性,使得有越来越多的 ...
- python读取表格数据_Python读取Excel数据并根据列名取值
一直想将自己接触到的东西梳理一遍,可就是迈不出第一步,希望从这篇总结开始不要再做行动的矮人了. 最近测试过程中需要用到python读取excel用例数据,于是去了解和学习了下xlrd库,这里只记录使用 ...
- python数据分析第一步:读取以及查看数据
用python做数据分析第一步,通常会遇到需要将现成文件(数据库里导出来,或者其他情况下获得的各种文件)拿来处理分析的情况,下面来说下利用python的标准库pandas来读取以及查看数据的方法 1. ...
最新文章
- protobufjs 命令执行_【原码笔记】-- protobuf.js 与 Long.js
- 网站推广专员浅析不做大幅修改如何调整网站推广内容?
- Python_sqlalchemy——创建、查询、删除、更新一对多的表
- 岗位推荐 | 腾讯音乐娱乐招聘推荐算法工程师、推荐后台工程师
- 使用js将后台返回的数据转换成树形结构
- 椭圆极点极线性质_【气贯长虹】教你认清极点极线的真面目虽粗浅,但绝对受益!!!...
- js引用类型和基本类型、隐式类型转换以及强制类型转换面试题
- 小程序毕设作品之微信小程序点餐系统毕业设计(4)开题报告
- Navicat Premium 12安装包下载
- uni-app 打包小程序体验版
- 2021李彦宏致股东信全文
- LeetCode T32 Longest Valid Parentheses
- 最短路默写1最短路默写2
- 服务器芯片和一般电脑芯片的区别,服务器CPU和PC的CPU区别
- 转:授之于鱼还是授之以渔,金蝶给了企业SaaS一个完整答案
- 阿里云全站加速 DCDN 升级
- 使用模拟退火算法解决TSP问题
- 如何使用JS实现banner图滚动
- iPhone 越狱版本打包
- 矩阵求逆引理(Matrix Inversion Lemma)的意义
热门文章
- Java实现自动输入账号密码登陆软件
- 为什么新冠德尔塔毒株如此“危险”?
- 这不是而且不能成为“一切照旧”
- 「分辨率比拼」还不够,4D成像雷达进入“软”竞争时代
- 云主机搭建Git服务器
- python 通过ftp自动 上传指定excel文件
- Got a packet bigger than 'max_allowed_packet' bytes 问题的解决方法
- 智慧厕所智能卫生间系统有哪些功能
- php empty 和空字符串区别
- 刺激战场测试fps软件,腾讯手游助手玩刺激战场怎样设置显示帧数?