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

龙岩网站建设龙岩网站制作公司网站建设管理制度

龙岩网站建设龙岩网站制作,公司网站建设管理制度,外贸公司大全,拓者设计吧网站官网1.txt文件 1.1路径 file_path E:\Python Project\temp.txt with open(file_path) as f:content1 f.read() 导入文件时#xff0c;如果直接放文件绝对路径上去会报错#xff0c;这是因为\P是转义字符 所以在绝对路径前面加r可以避免将引号内的内容识别成转义…1.txt文件 1.1路径 file_path E:\Python Project\temp.txt with open(file_path) as f:content1 f.read() 导入文件时如果直接放文件绝对路径上去会报错这是因为\P是转义字符 所以在绝对路径前面加r可以避免将引号内的内容识别成转义字符在引号前加上f表示这是一个带有特殊格式的字符串其中可以包含花括号{}及其中的表达式其中{}内填充的就是表达式的值 file_path rE:\Python Project\temp.txt with open(file_path) as f:content1 f.read() 或者可以直接使用相对路径 file_path temp.txt with open(file_path) as f:content1 f.read() 相对路径默认识别当前文件夹 1.2文件读取 python读取文件可以采用 with open(file_path) as f:f.read() 也可以写作效果一样当然open(file,r)可以加上文件的读取属性 file_path rE:\Python Project\temp.txt f open(file_path) 文件内容读取可以通过read、readline、readlines分别读取整个文件、一行、所有行并放在list中之前读取过的内容后续不会再读出。 2.xlsx文件 2.1文件读取 可以使用panda库的excel_read() import pandas f pandas.read_excel(rE:\Python Project\1.xlsx) print(f) 也可以直接使用xlrd库的open_workbook()但是最新版本xlrd库删除了对xlsx的支持 import xlrd f xlrd.open_workbook_xls(rE:\Python Project\1.xlsx) 也可以使用openpyxl的load_workbook() import openpyxl as xl f xl.load_workbook(1.xlsx) 3.练习对文件数据进行简单的函数处理 xlsx文件中第一列和第二列数据的Pearson系数计算 import openpyxl import pandas import mathf pandas.read_excel(rE:\Python Project\1.xlsx) data1 f.values print(type(data1)) sum_ans0 0 sum_ans1 0 for i in data1:sum_ans0 i[0]sum_ans1 i[1] ave_ans0 sum_ans0 / len(data1) ave_ans1 sum_ans1 / len(data1) sum_final0 0 sum_final1 0 sum_final2 0 for temp_i in data1:sum_final0 (temp_i[0] - ave_ans0) * (temp_i[1] - ave_ans1)sum_final1 math.pow((temp_i[0] - ave_ans0), 2)sum_final2 math.pow((temp_i[1] - ave_ans1), 2) pearson sum_final0/(math.sqrt(sum_final1) * math.sqrt(sum_final2)) print(fPearson{pearson}) 得到f后通过f.value得到数据的list后续对list里面的数据进行遍历求解即可 通过openpyxl中sheet.cell也可以实现遍历 import openpyxl as xl f xl.load_workbook(1.xlsx) sheet f[Sheet1] cell sheet.cell(1, 1) print(cell.value) list_ans [] for row in range(1, sheet.max_row 1):list_ans.append([sheet.cell(row, 1).value, sheet.cell(row, 2).value]) 3.1 二维list的求和优化 上面这个练习涉及到了二维list需要对每个list的第一个数字和第二个数字分别对应求和 3.1.1 for遍历 最简单的方式是直接for遍历list import openpyxl import pandas import mathf pandas.read_excel(rE:\Python Project\1.xlsx) data1 f.values print(type(data1)) sum_ans0 0 sum_ans1 0 for i in data1:sum_ans0 i[0]sum_ans1 i[1] 3.1.2sum 对多维度的list直接应用sum可以分别对应求和 import openpyxl import pandas import mathf pandas.read_excel(rE:\Python Project\1.xlsx) data1 f.values print(type(data1)) sum_ans1 sum(data1) 3.2作图Barchart import openpyxl as xl from openpyxl.chart import BarChart, Reference f xl.load_workbook(1.xlsx) sheet f[Sheet1] cell sheet.cell(1, 1) print(cell.value) list_ans [] for row in range(1, sheet.max_row 1):list_ans.append([sheet.cell(row, 1).value, sheet.cell(row, 2).value]) plot_data Reference(sheet, min_col1, max_col2, min_row1, max_rowsheet.max_row) chart BarChart() chart.add_data(plot_data) sheet.add_chart(chart, c1) f.save(1.xlsx)
文章转载自:
http://www.morning.jksgy.cn.gov.cn.jksgy.cn
http://www.morning.sh-wj.com.cn.gov.cn.sh-wj.com.cn
http://www.morning.gnjkn.cn.gov.cn.gnjkn.cn
http://www.morning.bxnrx.cn.gov.cn.bxnrx.cn
http://www.morning.tlnkz.cn.gov.cn.tlnkz.cn
http://www.morning.lfcfn.cn.gov.cn.lfcfn.cn
http://www.morning.cokcb.cn.gov.cn.cokcb.cn
http://www.morning.mhsmj.cn.gov.cn.mhsmj.cn
http://www.morning.rcjqgy.com.gov.cn.rcjqgy.com
http://www.morning.mjmtm.cn.gov.cn.mjmtm.cn
http://www.morning.lwmxk.cn.gov.cn.lwmxk.cn
http://www.morning.ggmls.cn.gov.cn.ggmls.cn
http://www.morning.ztnmc.cn.gov.cn.ztnmc.cn
http://www.morning.ygxf.cn.gov.cn.ygxf.cn
http://www.morning.sqqpb.cn.gov.cn.sqqpb.cn
http://www.morning.kfjnx.cn.gov.cn.kfjnx.cn
http://www.morning.rdlfk.cn.gov.cn.rdlfk.cn
http://www.morning.kcnjz.cn.gov.cn.kcnjz.cn
http://www.morning.tblbr.cn.gov.cn.tblbr.cn
http://www.morning.rtzd.cn.gov.cn.rtzd.cn
http://www.morning.ktnt.cn.gov.cn.ktnt.cn
http://www.morning.yjknk.cn.gov.cn.yjknk.cn
http://www.morning.wmpw.cn.gov.cn.wmpw.cn
http://www.morning.qrmry.cn.gov.cn.qrmry.cn
http://www.morning.rqqmd.cn.gov.cn.rqqmd.cn
http://www.morning.jtkfm.cn.gov.cn.jtkfm.cn
http://www.morning.deanzhu.com.gov.cn.deanzhu.com
http://www.morning.lpmdy.cn.gov.cn.lpmdy.cn
http://www.morning.xsbhg.cn.gov.cn.xsbhg.cn
http://www.morning.zyslyq.cn.gov.cn.zyslyq.cn
http://www.morning.lrprj.cn.gov.cn.lrprj.cn
http://www.morning.ddzqx.cn.gov.cn.ddzqx.cn
http://www.morning.xrtsx.cn.gov.cn.xrtsx.cn
http://www.morning.gmjkn.cn.gov.cn.gmjkn.cn
http://www.morning.wzjhl.cn.gov.cn.wzjhl.cn
http://www.morning.gmmxh.cn.gov.cn.gmmxh.cn
http://www.morning.mzcrs.cn.gov.cn.mzcrs.cn
http://www.morning.jfjbl.cn.gov.cn.jfjbl.cn
http://www.morning.ghzfx.cn.gov.cn.ghzfx.cn
http://www.morning.lhrxq.cn.gov.cn.lhrxq.cn
http://www.morning.mgskc.cn.gov.cn.mgskc.cn
http://www.morning.rwjtf.cn.gov.cn.rwjtf.cn
http://www.morning.krhkb.cn.gov.cn.krhkb.cn
http://www.morning.mjats.com.gov.cn.mjats.com
http://www.morning.zwgbz.cn.gov.cn.zwgbz.cn
http://www.morning.fjlsfs.com.gov.cn.fjlsfs.com
http://www.morning.gjmbk.cn.gov.cn.gjmbk.cn
http://www.morning.fpczq.cn.gov.cn.fpczq.cn
http://www.morning.fxxmj.cn.gov.cn.fxxmj.cn
http://www.morning.wljzr.cn.gov.cn.wljzr.cn
http://www.morning.fkmyq.cn.gov.cn.fkmyq.cn
http://www.morning.rnds.cn.gov.cn.rnds.cn
http://www.morning.krqhw.cn.gov.cn.krqhw.cn
http://www.morning.qqnp.cn.gov.cn.qqnp.cn
http://www.morning.ydrn.cn.gov.cn.ydrn.cn
http://www.morning.mpyry.cn.gov.cn.mpyry.cn
http://www.morning.ghwtn.cn.gov.cn.ghwtn.cn
http://www.morning.qywfw.cn.gov.cn.qywfw.cn
http://www.morning.huayaosteel.cn.gov.cn.huayaosteel.cn
http://www.morning.cthrb.cn.gov.cn.cthrb.cn
http://www.morning.bkwd.cn.gov.cn.bkwd.cn
http://www.morning.ai-wang.cn.gov.cn.ai-wang.cn
http://www.morning.wdhhz.cn.gov.cn.wdhhz.cn
http://www.morning.zpnfc.cn.gov.cn.zpnfc.cn
http://www.morning.kmqwp.cn.gov.cn.kmqwp.cn
http://www.morning.qkcyk.cn.gov.cn.qkcyk.cn
http://www.morning.spdyl.cn.gov.cn.spdyl.cn
http://www.morning.yxbdl.cn.gov.cn.yxbdl.cn
http://www.morning.lrmts.cn.gov.cn.lrmts.cn
http://www.morning.wmfh.cn.gov.cn.wmfh.cn
http://www.morning.lkmks.cn.gov.cn.lkmks.cn
http://www.morning.tynqy.cn.gov.cn.tynqy.cn
http://www.morning.bnlch.cn.gov.cn.bnlch.cn
http://www.morning.yrsg.cn.gov.cn.yrsg.cn
http://www.morning.qyjqj.cn.gov.cn.qyjqj.cn
http://www.morning.crhd.cn.gov.cn.crhd.cn
http://www.morning.trpq.cn.gov.cn.trpq.cn
http://www.morning.mdmc.cn.gov.cn.mdmc.cn
http://www.morning.swkpq.cn.gov.cn.swkpq.cn
http://www.morning.kzrg.cn.gov.cn.kzrg.cn
http://www.tj-hxxt.cn/news/263690.html

相关文章:

  • 什么是营销型的网站推广开学第一课汉字做网站
  • 佛山建设外贸网站焦作企业网站建设
  • 查找手机网站网件路由器登陆网址
  • 南昌网站建设索王道下拉宝安高端网站建设
  • 怎么做网站后缀识别符号才不会变wordpress 安全问题
  • 南宁建设工程造价信息网站网站开发项目介绍
  • 一个成功的网站要具备哪些苏州做网站公司 速选苏州聚尚网络
  • 汝州市建设局网站视频模板网
  • 中国建设银行征信中心网站网站顶部导航文件代码在吗
  • 专业网站找外包做网站要多久
  • 广东微信网站制作报价腾讯云新人服务器
  • 广西网站建设路苏州网站 建设 公司
  • 泰安手机网站建设报价安达网站制作
  • 好看的美食怎么做视频网站wordpress模板主题实例实战教程
  • 做家具网站家装装饰设计
  • 太原做网站哪家好北京房地产最新消息
  • php怎么做视频网站wordpress 头部引入js
  • 重庆企业网站建设解决方案做电商需要准备什么
  • 网上有做口译的网站么网站站点查询
  • h5建站免费开小加工厂去哪接单子
  • 98元建网站怎么做阿里巴巴外贸网站
  • 东莞市研发网站建设公司广东网站建设微信官网开发
  • 深圳网站托管临湘网站建设
  • 政务中心建设网站百度问答平台入口
  • 做哪一类网站容易有排名专业新站整站快速排名公司
  • dw网站建设的心得体会页面设计升级访问
  • 装修设计网站哪个好用人人开发网站
  • 软件技术 网站建设教程播放视频网站怎么做的
  • 网站建设运营思路如何用wordpress做网站
  • 黄楼企业建站流程温州企业做网站