蓝绝

博客园 首页 新随笔 联系 订阅 管理
  232 随笔 :: 1 文章 :: 0 评论 :: 25926 阅读

10 2022 档案

摘要:插入一列 .insert_cols(idx=数字编号) 插入多列 .insert_cols(idx=数字编号,amount=要插入的列数) 插入一行 .insert_rows(idx=数字编号) 插入多行 .insert_rows(idx=数字编号,amount=要插入的行数) 删除列 .delet 阅读全文
posted @ 2022-10-30 21:59 蓝绝 阅读(267) 评论(0) 推荐(0) 编辑

摘要:1.创建工作簿和工作表 workbook=openpyxl.Workbook() #创建工作簿 sheet=workbook.create_sheet() #创建工作表 2.向某个格子写入内容 sheet[‘A1’]=‘hello,Python’ 3.用某个格子写入内容 cell.value=‘he 阅读全文
posted @ 2022-10-30 21:37 蓝绝 阅读(1660) 评论(0) 推荐(0) 编辑

摘要:#3.4 课堂小案例_找到41码鞋子的坐标 #coding:utf-8 import openpyxl workbook=openpyxl.load_workbook('京东鞋子评论信息.xlsx') sheet=workbook['评论信息'] cols=sheet['D'] #获取D列数据 co 阅读全文
posted @ 2022-10-30 20:53 蓝绝 阅读(24) 评论(0) 推荐(0) 编辑

摘要:3.获取一系列格式 sheet[‘A1:A5’] sheet[‘A’] sheet[‘A:C’] sheet[5] 4.指定行和列的范围,按行获取,按列获取 .iter_rows(min_row=最低行数,max_row=最高行数,min_col=最低列数,max_col=最高列数) .iter_c 阅读全文
posted @ 2022-10-29 17:47 蓝绝 阅读(172) 评论(0) 推荐(0) 编辑

摘要:Python打开及读取Excel表格内容 1.打开和读取表格数据 打开工作薄 load_workbook(文件名) 获取工作表 workbook[sheet名称] workbook.active 获取表格尺寸 sheet.dimensions 2.打开和读取表格数据 sheet[‘A1’] cell 阅读全文
posted @ 2022-10-29 15:52 蓝绝 阅读(2789) 评论(0) 推荐(0) 编辑

摘要:openpyxl模块 安装方式 在线安装方式: Windows 用户: pip install openpyxl Mac用户: pip3 install openpyxl 测试 Windows用户打开命令行 输入 python Mac 用户打开终端输入 python3 然后输入 import ope 阅读全文
posted @ 2022-10-29 14:30 蓝绝 阅读(97) 评论(0) 推荐(0) 编辑

摘要:2.15 创建压缩包 1 zipfile.ZipFile('压缩包.zip','w') .write(file) 创建压缩包并加入文件 #coding=utf-8 import zipfile file_lst=['demo1.py','demo2.py','demo3.py','demo4.py' 阅读全文
posted @ 2022-10-29 14:15 蓝绝 阅读(146) 评论(0) 推荐(0) 编辑

摘要:解压压缩包 zipobj.extract() #解压压缩包的某个文件 import zipfile with zipfile.ZipFile('我的文件夹.zip','r') as zipobj: zipobj.extract('我的文件夹/demo18.py', 'new_dir') #解压压缩包 阅读全文
posted @ 2022-10-28 21:58 蓝绝 阅读(76) 评论(0) 推荐(0) 编辑

摘要:#读取压缩包zip内文件 zipfile.ZipFile() .namelist() #读取压缩包内文件信息 .getinfo() #读取压缩文件 import zipfile with zipfile.ZipFile('我的文件夹.zip','r') as zipobj: print(zipobj 阅读全文
posted @ 2022-10-23 21:38 蓝绝 阅读(351) 评论(0) 推荐(0) 编辑

摘要:#重命名文件或文件夹 os.rename( 要重命名的文件/文件夹, 新的名称) #重命名文件或文件夹 import os os.rename('demo.py','new_name_demo.py') os.rename('我的文件夹2','mydir') '''总结 创建文件夹 os.mkdir 阅读全文
posted @ 2022-10-23 21:18 蓝绝 阅读(309) 评论(0) 推荐(0) 编辑

摘要:# 删除文件或文件夹。 #注意:python程序的删除是彻底的,回收站是找不到的,删除需谨慎 import os os.remove('note.txt') #删除文件,用os模块 import shutil shutil.rmtree('第一层文件夹') #删除文件夹,用shutil模块 阅读全文
posted @ 2022-10-23 21:11 蓝绝 阅读(56) 评论(0) 推荐(0) 编辑

摘要:#2.10 移动文件和文件夹 shutil.move(要移动的文件/文件夹, 要移动到的位置 ) #移动文件或文件夹 import shutil #移动到文件夹下,( ‘我的文件夹/ ’ 的 ‘/’ 建议填写) shutil.move('new_dir/new_python.py','我的文件夹/' 阅读全文
posted @ 2022-10-23 21:00 蓝绝 阅读(157) 评论(0) 推荐(0) 编辑

摘要:#复制文件:shutil.copy(要复制的文件 , 要复制文件的位置) #复制文件夹:shutil.copytree(要复制的文件夹 , 要复制文件夹的位置) #复制文件:shutil.copy(要复制的文件 , 要复制文件的位置) import shutil shutil.copy('demo1 阅读全文
posted @ 2022-10-23 20:49 蓝绝 阅读(312) 评论(0) 推荐(0) 编辑

摘要:#创建单层文件夹os.mkdir(新文件夹名称) #创建多层文件夹os.makedirs(新文件夹名称) #创建单层文件夹os.mkdir(新文件夹名称) import os #os.mkdir("我的文件夹") #如果要创建的新文件夹已存在,程序会报错 #在创建文件夹之前,先判断要创建文件夹是否存 阅读全文
posted @ 2022-10-23 20:28 蓝绝 阅读(194) 评论(0) 推荐(0) 编辑

摘要:#创建临时文件存储数据TemporaryFile(),创建临时文件 #创建临时文件夹 TemporaryDirectory(),创建临时文件夹 #TemporaryFile(),创建临时文件 from tempfile import TemporaryFile file=TemporaryFile( 阅读全文
posted @ 2022-10-20 22:09 蓝绝 阅读(237) 评论(0) 推荐(0) 编辑

摘要:#读取文件内容 f=open('note.txt','r',encoding='utf-8') #有中文使用encoding='utf-8' text=f.readlines() print(text) f.close() #推荐的使用的方式 with...as 上下文管理器 with open(' 阅读全文
posted @ 2022-10-20 21:39 蓝绝 阅读(35) 评论(0) 推荐(0) 编辑

摘要:# 查询文件信息 .stat() import os for file in os.scandir(): #扫描目录文件 print(file.stat()) #查询文件具体的详细信息 import os print(os.stat('demo.py')) #查询指定文件具体的详细信息 #运行输出第 阅读全文
posted @ 2022-10-08 22:07 蓝绝 阅读(38) 评论(0) 推荐(0) 编辑

摘要:#搜索匹配文件 字符串内置方法 startswith() endswith() #glob模块。匹配所有 * 匹配任意单个字符 ? 匹配seq中的任何字符[seq] 匹配任何不在seq中的字符[!seq] #fnmatch模块:fnmatch. fnmatch(filename, pattern)  阅读全文
posted @ 2022-10-08 20:53 蓝绝 阅读(37) 评论(0) 推荐(0) 编辑

摘要:#遍历文件 ##把文件夹里面的文件夹里的文件夹里的文件都找出来 os.walk(xxx) import os print(os.walk('./')) for dirpath,dirnames,files in os.walk('./'): print('发现文件夹',dirpath) print( 阅读全文
posted @ 2022-10-06 22:11 蓝绝 阅读(52) 评论(0) 推荐(0) 编辑

摘要:# listdir(path)返回指定目录下的文件和信息 ,os.listdir()。(注意:返回的是str类型) import os print(os.listdir()) #listdir(path)返回指定目录下的文件和信息 lst=os.listdir() for item in lst: 阅读全文
posted @ 2022-10-06 21:55 蓝绝 阅读(100) 评论(0) 推荐(0) 编辑

摘要:#os模块简介 ##os模块 ###Python标准库 ###和操作系统有关的操作 ###创建、移动、复制文件和文件夹 ###文件路径和名称处理 #路径的操作 ##获取当前Python程序运行路径 ###不同操作系统之间路径的表示方式 ###windows中采用反斜杠(\)作为文件夹之间的分隔符 # 阅读全文
posted @ 2022-10-06 21:23 蓝绝 阅读(35) 评论(0) 推荐(0) 编辑

摘要:#模块 #一个.py结尾的文件就是一个模块 函数、类和模块之前的关系 如何使用别人写好的模块 安装模块 pip install 模块名称 #导入模块 import 模块名称 from 模块名称 import 具体函数、类... #以主程序的形式执行 if __name__ ==‘__main__’: 阅读全文
posted @ 2022-10-06 20:37 蓝绝 阅读(61) 评论(0) 推荐(0) 编辑

摘要:#类的创建和类的对象实例化调用(类中的函数叫方法) class Girl:#类(别) #创建类 def __init__(self,hair,name,age): self.hair=hair self.name=name self.age=age def eat(self): print(self 阅读全文
posted @ 2022-10-06 20:03 蓝绝 阅读(12) 评论(0) 推荐(0) 编辑

摘要:#函数中已经输出结果,调用函数即可 def fun(x): #函数体 print(x/10) fun(10) fun(20) #函数中未输出结果,调用函数,再输出结果 def calc(a,b): return a+b x=calc(10,20) y=calc(20,30) print(x) pri 阅读全文
posted @ 2022-10-06 19:45 蓝绝 阅读(15) 评论(0) 推荐(0) 编辑

摘要:#数据结构 –集合 #新增元素:dict_size.add(obj) #删除元素:dict_size.remove(obj) #集合的遍历 #集合转换成列表提取数据 #数据结构 –元组(不能新增,不能删除,不能修改。有索引和列表一致) #元组用索引获取元素 #元组的遍历 #新增元素:dict_siz 阅读全文
posted @ 2022-10-06 19:30 蓝绝 阅读(28) 评论(0) 推荐(0) 编辑

摘要:#字典的增删改 #获取值元素:dict_size[key] #新增元素:dict_size[key]=value #修改元素:dict_size[key]=new_value #删除元素:del dict_size[key] #字典的遍历,key的遍历和value的遍历 #字典的增删改 dict_s 阅读全文
posted @ 2022-10-06 13:38 蓝绝 阅读(52) 评论(0) 推荐(0) 编辑

摘要:#列表的数据处理 #1.获取元素:lst[index] #2.新增元素:lst.append(obj) #3.修改元素:lst[index]=obj #4.删除元素:lst.remove(obj) #5.列表元素很多批量处理 for...in.. #6.列表数据获取中的切片 ———————————— 阅读全文
posted @ 2022-10-06 13:05 蓝绝 阅读(123) 评论(0) 推荐(0) 编辑

摘要:#for ... in... 遍历循环 for i in range(1,6): #数字遍历 print(i) for ch in 'Python': # 字符串遍历 print(ch) #循环结构的 while 循环 a=1 while a<=5: #放行条件 print(a) #分别换行输出 1 阅读全文
posted @ 2022-10-06 12:22 蓝绝 阅读(93) 评论(0) 推荐(0) 编辑

摘要:age=input('你几岁了?') print(age) '''由计算机提问而得到的任何回答,统统为字符串str类型''' print(type(age)) age=int(age) #类型转换"机" print(type(age)) F:\python3\python_3.8.3\python. 阅读全文
posted @ 2022-10-06 11:30 蓝绝 阅读(41) 评论(0) 推荐(0) 编辑

摘要:#数据类型 '''字符串类型str:可以是单引号,双引号和 3引号''' a='HELLO' b="HELLO" c='''HE LLO''' d="""HELLO""" print(a) print(b) print(c) print(d) age=20 print(age) #整数类型int h 阅读全文
posted @ 2022-10-06 11:24 蓝绝 阅读(17) 评论(0) 推荐(0) 编辑

摘要:print() 函数 和 变量与赋值 num=100 print(num) F:\python3\python_3.8.3\python.exe E:/PycharmProjects/pythonProject/demon1/chap3/demo2.py 100 进程已结束,退出代码0 阅读全文
posted @ 2022-10-05 22:09 蓝绝 阅读(45) 评论(0) 推荐(0) 编辑

摘要:# balance=1000 #银行卡的上的余额 money=input('请输入取款金额:') #输入取款金额 money=int(money) #能过类型转换机,将str类型转换成int类型 if money<=balance: #判断, 取款金额与银行卡上的余额进行的比较 balance=ba 阅读全文
posted @ 2022-10-05 21:57 蓝绝 阅读(51) 评论(0) 推荐(0) 编辑

摘要:import os.path print('1.',os.path.abspath('demo13.py')) #获取文件或目录绝对路径 print('2.',os.path.exists('demo13.py'),os.path.exists('demo18.py')) #判断文件和目录是否存在 阅读全文
posted @ 2022-10-05 21:38 蓝绝 阅读(34) 评论(0) 推荐(0) 编辑

摘要:#目录操作 #os模块是Python内置的与操作系统功能和文件系统相关的模块,该模块中的语句的执行结果通常与操作系统有关,在不同的操作系统上运行,得到的结果可能不一样。 #os模块与os.path模块用于对目录或文件进行操作 #os模块与操作系统相关的一个模块 import os os.system 阅读全文
posted @ 2022-10-04 20:35 蓝绝 阅读(60) 评论(0) 推荐(0) 编辑

摘要:#with语句确保,不论是否运行错误都确保文件关闭, with open('a.txt','r') as file: print(file.read()) # MyContentMgr实现了特殊方法__enter__(),__exit__()称为该类对象遵守了上下文管理器协议该类对象的实例对象,称为 阅读全文
posted @ 2022-10-04 20:02 蓝绝 阅读(12) 评论(0) 推荐(0) 编辑

摘要:# 读,输出 read(), read([size]) , readline(), readlines() file = open('a.txt','r') print('输出文本所有内容',file.read()) # 输出文本所有内容 file.close() file = open('a.tx 阅读全文
posted @ 2022-10-04 18:59 蓝绝 阅读(43) 评论(0) 推荐(0) 编辑

摘要:file=open('a.txt','w') #a.txt 如果没有就会创建新的文件 file.write('python') #文件写入python file.close() file=open('a.txt','a') # a 文件追加内容 file.write('python1') file. 阅读全文
posted @ 2022-10-03 22:05 蓝绝 阅读(49) 评论(0) 推荐(0) 编辑

摘要:#pycharm 新建文件或其他文件默认为 UTF-8 格式,如果新建文件中有中文,就会读取失败,可把文件另存为其他格式(gbk) file=open('a.txt','r') #打开读取文件#需手动新建a.txt.文件 print(file.readline()) #输出读取文件内容 file.c 阅读全文
posted @ 2022-10-03 21:03 蓝绝 阅读(32) 评论(0) 推荐(0) 编辑

摘要: 阅读全文
posted @ 2022-10-03 20:17 蓝绝 阅读(22) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示