博文

RJDBC链接oracle数据库

1 安装RJDBC 2 安装 Oracle RJDBC驱动 ( JDBC and UCP Downloads page (oracle.com) ) 3 下载并赋予执行权限 chmod 755 ojdbc8.jar library(RJDBC) jdbcDriver =JDBC("oracle.jdbc.OracleDriver",classPath="/usr/bin/ojdbc8.jar") con =dbConnect(jdbcDriver, "jdbc:oracle:thin:@//192.168.30.48:1521/JZDB1", "username", "password")

R 地址拆分

library(tidyverse) library(lubridate) library(showtext) library(janitor) library(openxlsx) library(stringi) showtext_auto() #时间需要修改 yw_date <- ymd('2022-11-16') `%nin%` = Negate(`%in%`) place_cut <- function(data) {   m=stri_match_all_regex(data,'[中]{0,1}[国]{0,1}([\u4e00-\u9fa5]*?(?:省|自治区|市|新疆|广西|内蒙古|宁夏))([\u4e00-\u9fa5]*?(?:市|区|县|自治州|盟)){0,1}([\u4e00-\u9fa5]*?(?:市|区|县|旗)){0,1}([\u4e00-\u9fa5]*?(?:乡|镇|街道|苏木)){0,1}([\u4e00-\u9fa5]*?(?:\\S+)){0,1}')   sheng=m[[1]][,2]   shi=m[[1]][,3]   xian=m[[1]][,4]   dizhi=str_c(sheng,shi,xian,sep=',')   return(dizhi) } ka <- read.csv('/mnt/d/1116 24时/报告卡.csv',fileEncoding = 'GB18030') %>%    mutate(有效证件号=toupper(str_remove_all(有效证件号,"'")),          报告卡录入时间=ymd_hms(报告卡录入时间),          订正终审时间=case_when(str_detect(订正终审时间,"\\.") ~ "",                           TRUE  ~ as.character(订正终审时...

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/' )