xlrd

自动化不知如何参数化?xlrd来帮你解决

巧了我就是萌 提交于 2020-08-05 09:25:02
平时在做自动化测试的时候,一直都是要求数据与业务逻辑分离。把测试数据都写在业务里面的话,比较混杂。为了方便管理测试数据,所以引入了python的一个扩展库--xlrd。该库使用简单,能满足自动化测试的数据分离的需求。 闲语少聊,我们直接来看,xlrd是如何完成数据读取的。 安装 安装很简单,方式①:直接命令pip install xlrd;方式②:在Pycharm中直接安装即可。 基础命令 ①打开excel文件并创建对象 excel_object = xlrd.open_workbook(excel_path) ②根据工作表名称获取数据 sheet_object = excel_object.sheet_by_name('Sheet1') ③获取excel文件中所有工作表名称 print(excel_object.sheet_names()) ④获取有效行数 row_nrows = sheet_object.nrows ⑤获取有效列数 col_ncols = sheet_object.ncols ⑥获取当前行的单元格长度 row_length = sheet_object.row_len(1) ⑦获取第一行数据 rows_cell_value = sheet_object.row_values(0) ⑧获取坐标为第一行、第一列单元格数据 row_cell_value1 =

Python如何连接Mysql及基本操作

耗尽温柔 提交于 2020-08-04 22:40:31
什么要做python连接mysql,一般是解决什么问题的   做自动化测试时候,注册了一个新用户,产生了多余的数据,下次同一个账号就无法注册了,这种情况怎么办呢?自动化测试都有数据准备和数据清理的操作,如果因此用例产生了多余数据,就需要清理数据,可以用Pyhthon连接Mysql直接删除多余的数据就可以了。   Python3如何连接Mysql呢?PyMySQL是在Py3版本用于连接Mysql python连接mysql的模块安装 在线安装 在Pycharm---点击--Terminal---输入pip install PyMySQL等待完装完毕即可,如图所示 离线安装 有时候在线安装第三方模块的时,会因为网络原因总是装不上,那怎么办呢?那就手动安装 下载所需要的模块包 解压该文件 将文件名改短,然后放入非C盘且放在根目录 打开cmd---->E:---->cd xlrd---->python setup.py install 等待完装完毕 导入模块 import xlrd,运行如果没报错就说明安装正常 连接MySql import pymysql # 打开数据库连接 db = pymysql.connect("localhost", "root", "111223", "study_date") # 使用 cursor() 方法创建一个游标对象 cursor cursor =

python处理word和excel文件

假装没事ソ 提交于 2020-08-04 16:30:39
python处理word和excel表格数据 学习过程中遇到批量将excel表格数据填入到word的问题,对于excel的函数使用不是很熟悉,python中有处理word和excel的库,所以学习使用python实现对数据的批量处理。首先是需要了解处理word和excel的具体操作。 python对编辑word表格 需要安装第三方库python-docx python-docx API网址: https://python-docx.readthedocs.io/en/latest/#api-documentation 对表格的基本操作 # -*- coding: utf-8 -*- from docx import Document from docx.enum.text import WD_ALIGN_PARAGRAPH from docx.oxml.ns import qn from docx.shared import Pt path=r'C:\Users\hxy\Desktop\test.docx'#文件路径 doc=Document(path)#读入文件 #设置表格字体 doc.styles['Normal'].font.name = u'仿宋' doc.styles['Normal']._element.rPr.rFonts.set(qn('w:eastAsia'),

How to speed up import of large xlsx files?

最后都变了- 提交于 2020-08-02 19:32:09
问题 I want to process a large 200MB Excel (xlsx) file with 15 sheets and 1 million rows with 5 columns each) and create a pandas dataframe from the data. The import of the Excel file is extremely slow (up to 10minutes). Unfortunately, the Excel import file format is mandatory (I know that csv is faster...). How can I speed up the process of importing a large Excel file into a pandas dataframe? Would be great to get the time down to around 1-2 minutes, if possible, which would be much more

How to speed up import of large xlsx files?

和自甴很熟 提交于 2020-08-02 19:30:49
问题 I want to process a large 200MB Excel (xlsx) file with 15 sheets and 1 million rows with 5 columns each) and create a pandas dataframe from the data. The import of the Excel file is extremely slow (up to 10minutes). Unfortunately, the Excel import file format is mandatory (I know that csv is faster...). How can I speed up the process of importing a large Excel file into a pandas dataframe? Would be great to get the time down to around 1-2 minutes, if possible, which would be much more

Python pandas教程推荐

我的梦境 提交于 2020-07-29 07:50:08
简介 下面内容为github作者的Pandas学习笔记,目前是我看到最好的资料,没有之一。搬砖: https://github.com/datawhalechina/joyful-pandas/blob/master/README.md ​ github.com Joyful-Pandas 【本教程与Pandas官方最新发行版本保持同步,当前版本: v-1.0.3 】 【注意】使用教程前请务必将Pandas升级到最新版本,否则可能会有代码运行报错 一、写作初衷 在使用Pandas之前,几乎所有的大型表格处理问题都是用xlrd/xlwt和python循环实现,虽然这已经几乎能完成一切的需求,但其缺点也显而易见,其一就是速度问题,其二就是代码的复用性几乎为0。 曾经也尝试过去零星地学Pandas,但不得不说这个包实在太过庞大,每次使用总觉得盲人摸象,每个函数的参数也很多,学习的路线并不是十分平缓。如果你刚刚上手使用Pandas,那么在碎片的学习过程中,报错是常常发生的事,并且很难修(因为不理解内部的操作),即使修好了下次又不会,令人有些沮丧。 2019秋季,我偶然找到了一本完全关于Pandas的书,Theodore Petrou所著的Pandas Cookbook,现在可在网上下到pdf,不过现在还没有中文版。寒假开始后,立即快速地过了一遍,发现之前很多搞不清的概念得到了较好的解答

基于PO和单例设计模式用python+selenium进行ui自动化框架设计【多测师】

狂风中的少年 提交于 2020-07-29 06:00:23
一)框架目录的结构 二)config包当中的config.ini文件主要是用来存项目的绝对路径,是为了后续跑用例和生成测试报告做准备 然后目前的配置文件大都会用yaml,ini,excel,还有.py也就是python文件来进行管理这里用的是ini文件。 三)config包当中的globalconfig文件主要是用来生成项目的路径,测试用例,测试报告的路径 其中调用了ReadConfigIni这个类来读取ini格式的文件。 四)Data.xlsx主要是用来存放项目的url,账号和密码的 通过excel来存放,可以增加数据的稳定性,后面会通过封装读取excel文档的工具类,来对excel文档中的数据进行读取 五)public包中pages包中的BaseTestCase模块主要是用来放基类的 当中并且通过set_driver传入一个driver对象来进行设置driver对象,这其实就是单例设计模式的体现然后通过get_driver来拿driver, 所以只要继承BaseTestCase这个基类,就可以拿到这个类当中的一切类方法。然后定位页面元素 用find_element这个类方法来进行封装,可以使得传入的参数是一个 元组,然后这里其实用到了Java当中的page object设计模式,也就是所谓的PO设计模式,使得页面 中的每一个控件都变成了对象的属性。 六

使用Python中openpyxl库来操作Excel

徘徊边缘 提交于 2020-07-28 09:57:55
文章目录 执行 pip install openpyxl 安装该库 新建Excel,写入数据 下面的示例代码 修改Excel中的数据 修改单元格内容 删除行、删除列 文字 颜色、字体、大小 背景色 插入图片 Excel COM接口 执行 pip install openpyxl 安装该库 import os os . system ( "pip3 install openpyxl" ) 新建Excel,写入数据 xlrd 只能读取Excel内容,如果你要 创建 一个新的Excel并 写入 数据,可以使用 openpyxl 库。 openpyxl 库既可以读文件、也可以写文件、也可以修改文件。 但是,openpyxl 库不支持老版本 Office2003 的 xls 格式的Excel文档,如果要读写xls格式的文档,可以使用 Excel 进行相应的格式转化。 下面的代码,演示了 openpyxl 的 一些基本用法。 import openpyxl #创建一个Excel workbook 对象 book = openpyxl . Workbook ( ) #创建时,会自动产生一个sheet,通过active获取 sh = book . active #修改当前 sheet 标题为 工资表 sh . title = '工资表' #保存文件 book . save ( '信息.xlsx'

Open an excel from http website using xlrd

久未见 提交于 2020-06-28 06:42:25
问题 I trying to open an excel file from web using xlrd, in Python 3.5.4. import requests import xlrd import urllib link='http://www.bla.com/bla.xlsx' request = urllib.request.urlretrieve(link) workbook = xlrd.open_workbook(request) I'm getting this error. TypeError: invalid file: ('0xlxs', <http.client.HTTPMessage object at 0x04600590>) Anyone have a hint? Thanks! 回答1: The urlretrieve returns a tuple, not the url content. urllib.request.urlretrieve(url, filename=None, reporthook=None, data=None)

sheets of Excel Workbook from a URL into a `pandas.DataFrame`

倾然丶 夕夏残阳落幕 提交于 2020-05-24 20:25:07
问题 After looking at different ways to read an url link, pointing to a .xls file, I decided to go with using xlrd. I am having a difficult time converting a 'xlrd.book.Book' type to a 'pandas.DataFrame' I have the following: import pandas import xlrd import urllib2 link ='http://www.econ.yale.edu/~shiller/data/chapt26.xls' socket = urllib2.urlopen(link) #this line gets me the excel workbook xlfile = xlrd.open_workbook(file_contents = socket.read()) #storing the sheets sheets = xlfile.sheets() I