博文

目前显示的是 十月, 2022的博文

pathlib 学习

  import os import pathlib from pathlib import Path import aspose.words as aw def convert_path ( win_path ) : tmp_path = win_path.replace ( ":" , "" ) tmp_path = tmp_path.replace ( " \\ " , "/" ) tmp_path = tmp_path.lower () tmp_path = "/mnt/" + tmp_path return ( tmp_path ) url = pathlib.Path ( convert_path ( r"C:\Users\xuefe\Downloads\Video" ) ) files = list ( url.glob ( '*.*' ) ) # pathlib.PosixPath 转 字符串 for file in files: file= str ( file ) doc = aw.Document ( file, aw.loading.LoadOptions ( "2022" ) ) doc.save ( file ) # file_dir = convert_path(r"C:\Users\xuefe\Downloads\Video") # files = os.listdir(file_dir) # # for file in files: # file_p=os.path.join(file_dir,file) # print(type(file_p)) # doc = aw.Document(file_p, aw.loading.LoadOptions("2022")) # doc.save(file_p) cwd = pathlib.Path.cwd () # 获取当前目录 home = Path.home () # 获

tinytex包使用

 # 下载宏包,先修改为国内镜像源,比如改为清华大学的镜像源 tinytex::tlmgr_repo(url = "http://mirrors.tuna.tsinghua.edu.cn/CTAN/") tinytex::install_tinytex(version = "latest") tinytex::tlmgr_install('elegantbook') tinytex::tlmgr_install('fandol') #默认安装路径 tinytex::tinytex_root()  # 查看轻量级已包含哪些宏包 tl_pkgs()  # 解析错误日志,看看是缺什么宏包造成的 parse_packages("test.log")

pandas 条件赋值

  df["WhereCol"] = np.where((df.Cat == "A") & (df.B > 10), 1, 0) conditions = [ (df.Cat == "A") & (df.B > 10), (df.Cat == "B") & (df.B > 10) ] values = [1, 2] df["SelectCol"] = np.select(conditions, values, default=0) xg.case_when ( xg.A3.str.slice ( 16 , 17 ) .astype ( int ) % 2 == 0 , ' 女 ' , ~xg.A3.str.slice ( 16 , 17 ) .astype ( int ) % 2 == 0 , ' 男 ' , ' 不详 ' , column_name = " 性别 " ) xg=xg.case_when ( xg.A3.str.contains ( '^62' ) , ' 甘肃 ' , ~xg.A3.str.contains ( '^62' ) , ' 外省 ' , ' 其他 ' , column_name = " 归属 " )

pandas 链式操作

import pandas as pd import numpy as np import janitor yilanbiao=pd.read_excel ( convert_path ( r"C:\Users\xuefe\Desktop\ 未上报一览表 ( 截止 18 日 8 时 ).xlsx" ) ) ( yilanbiao. assign ( 身份证号 = lambda x: x [ ' 身份证号 ' ] .str.strip ( "'|’| , |“|‘" ) .str.upper () , 首次阳性采样时间 = lambda x:x [ ' 首次阳性采样时间 ' ] .pipe ( pd.to_datetime, unit = 's' ) ) . add_column ( column_name = "id" , value =yilanbiao [ ' 姓名 ' ] +yilanbiao [ ' 身份证号 ' ] ) ) ( yilanbiao. assign ( 身份证号 = lambda x:x [ ' 身份证号 ' ] .str.strip ( "'|’| , |“|‘" ) .str.upper () ) . concatenate_columns ( column_names = [ ' 姓名 ' , ' 身份证号 ' ] , new_column_name = 'id' , sep = '_' ) . drop_duplicates ( [ 'id' ] ) . drop ( [ 'id' ] , axis = 1 ) . also ( lambda x:x.to_excel ( r'/mnt/c/users/xuefe/desktop/ 去重复后 .xlsx' , index = False ) ) ) test= ( yilanbiao.also ( lambda x:x [ ' 身份证号 '

python 批量移除密码

  import msoffcrypto import pathlib def unlock ( filename, passwd, output_folder ) : temp = open ( filename, 'rb' ) excel = msoffcrypto.OfficeFile ( temp ) excel.load_key ( passwd ) out_path = pathlib.Path ( output_folder ) if not out_path.exists () : out_path.mkdir () with open ( str ( out_path/filename.name ) , 'wb' ) as f: excel.decrypt ( f ) temp.close () def convert_path ( win_path ) : tmp_path = win_path.replace ( ":" , "" ) tmp_path = tmp_path.replace ( " \\ " , "/" ) tmp_path = tmp_path.lower () tmp_path = "/mnt/" + tmp_path return ( tmp_path ) if __name__ == '__main__' : key= "2022" url = pathlib.Path ( convert_path ( r"C:\Users\xuefe\Downloads\Video" ) ) files = list ( url.glob ( '*.*' ) ) for f in files: unlock ( f, key, r'/mnt/c/users/xuefe/downloads/' )