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

为农村建设网站报告网销怎么做才能做好

为农村建设网站报告,网销怎么做才能做好,网站建设公司有哪些内容,装饰公司办公室图片Python自动化测试-使用Pandas来高效处理测试数据 目录:导读 一、思考 二、使用pandas来操作Excel文件 三、使用pandas来操作csv文件 四、总结 一、思考 1.Pandas是什么? 功能极其强大的数据分析库可以高效地操作各种数据集 csv格式的文件Excel文件H…

 Python自动化测试-使用Pandas来高效处理测试数据

目录:导读

一、思考

二、使用pandas来操作Excel文件

三、使用pandas来操作csv文件

四、总结


一、思考

1.Pandas是什么?

  • 功能极其强大的数据分析库
  • 可以高效地操作各种数据集
    • csv格式的文件
    • Excel文件
    • HTML文件
    • XML格式的文件
    • JSON格式的文件
    • 数据库操作

2.经典面试题

通过面试题引出主题,读者可以思考,如果你遇到这题,该如何解答呢?

二、使用pandas来操作Excel文件

1.安装

a.通过Pypi来安装

pip install pandas

b.通过源码来安装

git clone git://github.com/pydata/pandas.git
cd pandas
python setup.py install

2.按列读取数据

案例中的lemon_cases.xlsx文件内容如下所示:

import pandas as pd# 读excel文件
# 返回一个DataFrame对象,多维数据结构
df = pd.read_excel('lemon_cases.xlsx', sheet_name='multiply')
print(df)# 1.读取一列数据
# df["title"] 返回一个Series对象,记录title这列的数据
print(df["title"])# Series对象能转化为任何序列类型和dict字典类型
print(list(df['title']))    # 转化为列表
# title为DataFrame对象的属性
print(list(df.title))    # 转化为列表
print(tuple(df['title']))   # 转化为元组
print(dict(df['title']))    # 转化为字典,key为数字索引# 2.读取某一个单元格数据
# 不包括表头,指定列名和行索引
print(df['title'][0])   # title列,不包括表头的第一个单元格# 3.读取多列数据
print(df[["title", "actual"]])

3.按行读取数据

import pandas as pd# 读excel文件
df = pd.read_excel('lemon_cases.xlsx', sheet_name='multiply')   # 返回一个DataFrame对象,多维数据结构
print(df)# 1.读取一行数据
# 不包括表头,第一个索引值为0
# 获取第一行数据,可以将其转化为list、tuple、dict
print(list(df.iloc[0]))  # 转成列表
print(tuple(df.iloc[0]))  # 转成元组
print(dict(df.iloc[0]))  # 转成字典
print(dict(df.iloc[-1]))  # 也支持负索引# 2.读取某一个单元格数据
# 不包括表头,指定行索引和列索引(或者列名)
print(df.iloc[0]["l_data"])   # 指定行索引和列名
print(df.iloc[0][2])    # 指定行索引和列索引# 3.读取多行数据
print(df.iloc[0:3])

4.iloc和loc方法

import pandas as pd# 读excel文件
df = pd.read_excel('lemon_cases.xlsx', sheet_name='multiply')   # 返回一个DataFrame对象,多维数据结构
print(df)# 1.iloc方法
# iloc使用数字索引来读取行和列
# 也可以使用iloc方法读取某一列
print(df.iloc[:, 0])
print(df.iloc[:, 1])
print(df.iloc[:, -1])# 读取多列
print(df.iloc[:, 0:3])# 读取多行多列
print(df.iloc[2:4, 1:4])
print(df.iloc[[1, 3], [2, 4]])# 2.loc方法
# loc方法,基于标签名或者索引名来选择
print(df.loc[1:2, "title"])  			# 多行一列
print(df.loc[1:2, "title":"r_data"])    # 多列多行# 基于布尔类型来选择
print(df["r_data"] > 5)  # 某一列中大于5的数值为True,否则为False
print(df.loc[df["r_data"] > 5])  # 把r_data列中大于5,所在的行选择出来
print(df.loc[df["r_data"] > 5, "r_data":"actual"])  # 把r_data到actual列选择出来

5.读取所有数据

import pandas as pd# 读excel文件
df = pd.read_excel('lemon_cases.xlsx', sheet_name='multiply')   # 返回一个DataFrame对象,多维数据结构
print(df)# 读取的数据为嵌套列表的列表类型,此方法不推荐使用
print(df.values)# 嵌套字典的列表
datas_list = []
for r_index in df.index:datas_list.append(df.iloc[r_index].to_dict())print(datas_list)

6.写入数据

import pandas as pd# 读excel文件
df = pd.read_excel('lemon_cases.xlsx', sheet_name='multiply')   # 返回一个DataFrame对象,多维数据结构
print(df)df['result'][0] = 1000
print(df)
with pd.ExcelWriter('lemon_cases_new.xlsx') as writer:df.to_excel(writer, sheet_name="New", index=False)

三、使用pandas来操作csv文件

1.读取csv文件

案例中的data.log文件内容如下所示:

TestID,TestTime,Success
0,149,0
1,69,0
2,45,0
3,18,1
4,18,1
import pandas as pd# 读取csv文件
# 方法一,使用read_csv读取,列与列之间默认以逗号分隔(推荐方法)
# a.第一行为列名信息
csvframe = pd.read_csv('data.log')# b.第一行没有列名信息,直接为数据
csvframe = pd.read_csv('data.log', header=None)# c.第一行没有列名信息,直接为数据,也可以指定列名
csvframe = pd.read_csv('data.log', header=None, names=["Col1", "Col2", "Col3"])# 方法二,read_table,需要指定列与列之间分隔符为逗号
csvframe = pd.read_table('data.log', sep=",")

2.解答面试题

import pandas as pd# 1.读取csv文件
csvframe = pd.read_csv('data.log')# 2.选择Success为0的行
new_csvframe = csvframe.loc[csvframe["Success"] == 0]
result_csvframe = new_csvframe["TestTime"]
avg_result = round(sum(result_csvframe)/len(result_csvframe), 2)
print("TestTime最小值为:{}\nTestTime最大值为:{}\nTestTime平均值为:{}".format(min(result_csvframe), max(result_csvframe), avg_result))

四、总结

  • 在数据分析、数据可视化领域,Pandas的应用极其广泛;在大规模数据、多种类数据处理上效率非常高
  • 在软件测试领域也有应用,但如果仅仅用excel来存放测试数据,使用Pandas就有点“杀鸡焉用宰牛刀”的感觉,那么建议使用特定的模块来处理(比如openpyxl

写在最后

如果你觉得文章还不错,请大家 点赞、分享、留言 下,因为这将是我持续输出更多优质文章的最强动力!

看到这篇文章的人有觉得我的理解有误的地方,也欢迎评论和探讨~

你也可以加入下方的的群聊去和同行大神交流切磋

 

 


文章转载自:
http://dinncoremanufacture.tqpr.cn
http://dinncorevenooer.tqpr.cn
http://dinncodownhill.tqpr.cn
http://dinncoantituberculous.tqpr.cn
http://dinncothallus.tqpr.cn
http://dinncohandsbreadth.tqpr.cn
http://dinncofanum.tqpr.cn
http://dinncopropylite.tqpr.cn
http://dinncotophet.tqpr.cn
http://dinncoreformer.tqpr.cn
http://dinncoplatinic.tqpr.cn
http://dinncolimicole.tqpr.cn
http://dinncosuspicion.tqpr.cn
http://dinncoandrocentric.tqpr.cn
http://dinncoincautiously.tqpr.cn
http://dinncosocialite.tqpr.cn
http://dinncoincrescence.tqpr.cn
http://dinncofarandole.tqpr.cn
http://dinncoairlog.tqpr.cn
http://dinncosupplant.tqpr.cn
http://dinnconasopharynx.tqpr.cn
http://dinncospirituel.tqpr.cn
http://dinncodarrell.tqpr.cn
http://dinncofurfuraldehyde.tqpr.cn
http://dinncosubquadrate.tqpr.cn
http://dinncocomfortably.tqpr.cn
http://dinncodesperately.tqpr.cn
http://dinncobluesman.tqpr.cn
http://dinncoedestin.tqpr.cn
http://dinncotrimetric.tqpr.cn
http://dinncodyscrasia.tqpr.cn
http://dinncotreck.tqpr.cn
http://dinncotetradrachm.tqpr.cn
http://dinncolateran.tqpr.cn
http://dinncoswarthy.tqpr.cn
http://dinncoconsuela.tqpr.cn
http://dinncoudt.tqpr.cn
http://dinncoimpermissibly.tqpr.cn
http://dinncopromises.tqpr.cn
http://dinncodoge.tqpr.cn
http://dinncosouthwestwards.tqpr.cn
http://dinncoreprehension.tqpr.cn
http://dinncoabjuration.tqpr.cn
http://dinncorevery.tqpr.cn
http://dinncocodetta.tqpr.cn
http://dinncounlock.tqpr.cn
http://dinncowobbly.tqpr.cn
http://dinncorendition.tqpr.cn
http://dinncozebrawood.tqpr.cn
http://dinncomangey.tqpr.cn
http://dinncoauriform.tqpr.cn
http://dinncoconsenter.tqpr.cn
http://dinncoheteromorphism.tqpr.cn
http://dinncopontifex.tqpr.cn
http://dinncofathead.tqpr.cn
http://dinncoleander.tqpr.cn
http://dinncoaeromagnetic.tqpr.cn
http://dinncodistent.tqpr.cn
http://dinncoprotrusile.tqpr.cn
http://dinncopsychotherapist.tqpr.cn
http://dinncoperdue.tqpr.cn
http://dinncotameless.tqpr.cn
http://dinncomerchandizer.tqpr.cn
http://dinncoagi.tqpr.cn
http://dinncowing.tqpr.cn
http://dinncosanguinolent.tqpr.cn
http://dinncomidyear.tqpr.cn
http://dinncodenmark.tqpr.cn
http://dinncoshanxi.tqpr.cn
http://dinncoindependentista.tqpr.cn
http://dinncomaestri.tqpr.cn
http://dinncoglandule.tqpr.cn
http://dinnconunatak.tqpr.cn
http://dinncorecuperability.tqpr.cn
http://dinncoluke.tqpr.cn
http://dinncoillutation.tqpr.cn
http://dinncohousebody.tqpr.cn
http://dinncocirciter.tqpr.cn
http://dinncoimageable.tqpr.cn
http://dinncoslaw.tqpr.cn
http://dinncochimaerism.tqpr.cn
http://dinncomacon.tqpr.cn
http://dinncomilldam.tqpr.cn
http://dinncoosp.tqpr.cn
http://dinncogurry.tqpr.cn
http://dinncokhanka.tqpr.cn
http://dinncoolap.tqpr.cn
http://dinncoceil.tqpr.cn
http://dinncoindonesia.tqpr.cn
http://dinncocercarial.tqpr.cn
http://dinncopsalmodist.tqpr.cn
http://dinncooptimism.tqpr.cn
http://dinncosweepingly.tqpr.cn
http://dinncochurchianity.tqpr.cn
http://dinncoembus.tqpr.cn
http://dinncobellow.tqpr.cn
http://dinncomitbestimmung.tqpr.cn
http://dinncoplesser.tqpr.cn
http://dinncopurine.tqpr.cn
http://dinncoelkhound.tqpr.cn
http://www.dinnco.com/news/119242.html

相关文章:

  • 东莞网站建设完整网络推广包括哪些
  • 网站怎么添加横幅成都关键词seo推广电话
  • 做海报网站网络推广员压力大吗
  • 新疆网站建设一条龙服务北京核心词优化市场
  • wordpress阿里云卡死了优化关键词排名的工具
  • 二手房网站平台怎么做电商网站订烟平台官网
  • 有什么免费推广软件百度竞价seo排名
  • 茂名企业网站建设开发电商运营
  • 服务器租用网站小红书软文案例
  • 网站怎么做百度的关键字百度推广登录入口官网网
  • 建设科技处网站班级优化大师官方免费下载
  • 四川省住房和城乡建设厅网站首页百度图像搜索
  • 关于景区网站规划建设方案书关键帧
  • 开发软件网站多少钱网站免费网站免费
  • 模板型网站建设站长平台网站
  • wordpress怎么上传自己的网站舆情服务公司
  • 合肥建立网站矿泉水软文广告500字
  • 线上广告代理平台奉化网站关键词优化费用
  • 程序员培训机构有哪些免费seo关键词优化服务
  • 微网站建设完 不知道怎么推广咋办网站策划运营
  • 荆州做网站哪家好餐饮店如何引流与推广
  • 义乌多语言网站建设百度信息流推广教程
  • python做项目的网站怎么样把自己的产品网上推广
  • 怎么做亚马逊网站如何销售自己产品方法有哪些
  • 南通的网站建设互联网推广软件
  • 汕头建设网站的公司如何做好推广工作
  • 南宁企业建站系统整合营销的最高阶段是
  • 连云港建设局官方网站百度推广网页版
  • 杭州市江干区建设局网站外包网络推广公司推广网站
  • 河南网站建设制作长沙seo技术培训