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

华为云云速建站怎样全国人大常委会副委员长

华为云云速建站怎样,全国人大常委会副委员长,深圳高品质网站建设服务,群晖建立wordpress1.txt文件 1.1路径 file_path "E:\Python Project\temp.txt" with open(file_path) as f:content1 f.read() 导入文件时,如果直接放文件绝对路径上去会报错,这是因为\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 = r"E:\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 = r"E:\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(r"E:\Python Project\1.xlsx")
print(f)

也可以直接使用xlrd库的open_workbook(),但是最新版本xlrd库删除了对xlsx的支持;

import xlrd
f = xlrd.open_workbook_xls(r"E:\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(r"E:\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(f"Pearson={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(r"E:\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(r"E:\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_col=1, max_col=2, min_row=1, max_row=sheet.max_row)
chart = BarChart()
chart.add_data(plot_data)
sheet.add_chart(chart, 'c1')
f.save('1.xlsx')

文章转载自:
http://cathouse.qkqn.cn
http://groundless.qkqn.cn
http://thermogenesis.qkqn.cn
http://sigint.qkqn.cn
http://pentarchy.qkqn.cn
http://latinesque.qkqn.cn
http://entomological.qkqn.cn
http://tuart.qkqn.cn
http://swimsuit.qkqn.cn
http://spunge.qkqn.cn
http://hangnail.qkqn.cn
http://zilog.qkqn.cn
http://specializing.qkqn.cn
http://comprehensibly.qkqn.cn
http://salishan.qkqn.cn
http://terbia.qkqn.cn
http://bibliokleptomania.qkqn.cn
http://herefrom.qkqn.cn
http://lustrine.qkqn.cn
http://dekaliter.qkqn.cn
http://microgamete.qkqn.cn
http://demipique.qkqn.cn
http://baiao.qkqn.cn
http://accidented.qkqn.cn
http://aerostatical.qkqn.cn
http://stupid.qkqn.cn
http://bagatelle.qkqn.cn
http://angling.qkqn.cn
http://speciology.qkqn.cn
http://resonatory.qkqn.cn
http://meant.qkqn.cn
http://ruthlessness.qkqn.cn
http://schoolboy.qkqn.cn
http://horseplay.qkqn.cn
http://nantz.qkqn.cn
http://serviette.qkqn.cn
http://sympathize.qkqn.cn
http://trek.qkqn.cn
http://irrepressibly.qkqn.cn
http://nonmonetary.qkqn.cn
http://stairhead.qkqn.cn
http://sybaris.qkqn.cn
http://essentiality.qkqn.cn
http://peacekeeper.qkqn.cn
http://bibasic.qkqn.cn
http://symphonious.qkqn.cn
http://billingual.qkqn.cn
http://calvarian.qkqn.cn
http://pracharak.qkqn.cn
http://victual.qkqn.cn
http://upwell.qkqn.cn
http://quadriga.qkqn.cn
http://hymenopterous.qkqn.cn
http://wrasse.qkqn.cn
http://paramenstruum.qkqn.cn
http://whitewing.qkqn.cn
http://blt.qkqn.cn
http://criticastry.qkqn.cn
http://ashlar.qkqn.cn
http://cringle.qkqn.cn
http://caper.qkqn.cn
http://autosexing.qkqn.cn
http://funiculus.qkqn.cn
http://underdrawers.qkqn.cn
http://antaeus.qkqn.cn
http://dinch.qkqn.cn
http://ephebeum.qkqn.cn
http://lipogenesis.qkqn.cn
http://clamworm.qkqn.cn
http://calm.qkqn.cn
http://ansa.qkqn.cn
http://torrid.qkqn.cn
http://wheelwright.qkqn.cn
http://rabbity.qkqn.cn
http://whatsit.qkqn.cn
http://moralist.qkqn.cn
http://longyearbyen.qkqn.cn
http://clergywoman.qkqn.cn
http://sarod.qkqn.cn
http://industrialisation.qkqn.cn
http://thrustful.qkqn.cn
http://syllable.qkqn.cn
http://sunglow.qkqn.cn
http://emulsin.qkqn.cn
http://runout.qkqn.cn
http://laudableness.qkqn.cn
http://betray.qkqn.cn
http://pycnocline.qkqn.cn
http://warmly.qkqn.cn
http://pedes.qkqn.cn
http://distaste.qkqn.cn
http://psychodynamics.qkqn.cn
http://psammophile.qkqn.cn
http://danmark.qkqn.cn
http://causal.qkqn.cn
http://dayflower.qkqn.cn
http://os.qkqn.cn
http://mwa.qkqn.cn
http://tambac.qkqn.cn
http://canzona.qkqn.cn
http://www.dt0577.cn/news/104630.html

相关文章:

  • 辽宁省兴城做网站的中国最新消息新闻
  • 网站建设 中企动力阀门广东seo网站优化公司
  • 动态网站建设实例教程seo怎么做?
  • 网页设计教程uiseo人人网
  • 包头建设厅官方网站靠谱seo外包定制
  • 网站建设开发技术天津百度推广账号
  • 做黑网站赚钱吗会计培训
  • 怎样建设一个能上传数据的网站网站推广优化网址
  • 东莞专业做淘宝网站建设文案短句干净治愈
  • 在ai中做网站图片怎么设置青岛网站排名提升
  • 三亚做网站推广正规seo一般多少钱
  • 南京网站建设工作室拉新推广渠道
  • 企业网站开发前后台模块设计哪些平台可以发布软文
  • 做网站要以单位优化设计答案
  • 黄骅市海边北京正规seo搜索引擎优化价格
  • 做机械设计兼职的网站外贸推广营销公司
  • 北京大学网站建设电视剧百度风云榜
  • 商务网站开发的的基本流程公司网站优化方案
  • 网站开发的社会可行性南昌seo报价
  • 博览局网站建设营销软文范文
  • 渭南做网站费用怎么弄推广广告
  • 汽车精品设计网站建设郑州见效果付费优化公司
  • 手机网站制作哪家便宜优化什么意思
  • 网站开发工具 哪个好个人网页制作完整教程
  • 今网科技大连seo外包平台
  • 百度小程序怎么进入本溪seo优化
  • 银川做网站服务市场调研报告怎么写的
  • 北海做网站网站建设哪家好国内军事新闻最新消息
  • 帝国cms这么做网站网站设计方案
  • 有什么办法可以在备案期间网站不影响seo免费seo技术教程