本节目录

  • 常用函数一:sel文件转换

  • 常用函数二:refwork文件转换

  • 常用函数三:xml文档解析

  • 常用函数四:文本分词

常用函数一:sel文件转换

sel是种特殊的文件格式,具体应用场景的话可以在搜狗细胞词库中看到,经常在做文本处理,分词的时候需要一些词典,那么搜狗细胞词库中的一些相关词库就会被使用,而这种sel文件格式不能直接使用,需要进行转换,转换成txt文件之后就可以去做进一步使用了,转换的代码是从网上找到,我自己也是用过多次,使用的时候可以直接拿来用。

  1. # -*- coding:utf-8 -*-
  2. """
  3. @author:Zhang Yafei
  4. @time: 2019/12/26
  5. Description: scel 文件格式转换
  6. """
  7. import struct
  8. import os
  9.  
  10. # 搜狗的scel词库就是保存的文本的unicode编码,每两个字节一个字符(中文汉字或者英文字母)
  11. # 找出其每部分的偏移位置即可
  12. # 主要两部分
  13. # 1.全局拼音表,貌似是所有的拼音组合,字典序
  14. # 格式为(index,len,pinyin)的列表
  15. # index: 两个字节的整数 代表这个拼音的索引
  16. # len: 两个字节的整数 拼音的字节长度
  17. # pinyin: 当前的拼音,每个字符两个字节,总长len
  18. #
  19. # 2.汉语词组表
  20. # 格式为(same,py_table_len,py_table,{word_len,word,ext_len,ext})的一个列表
  21. # same: 两个字节 整数 同音词数量
  22. # py_table_len: 两个字节 整数
  23. # py_table: 整数列表,每个整数两个字节,每个整数代表一个拼音的索引
  24. #
  25. # word_len:两个字节 整数 代表中文词组字节数长度
  26. # word: 中文词组,每个中文汉字两个字节,总长度word_len
  27. # ext_len: 两个字节 整数 代表扩展信息的长度,好像都是10
  28. # ext: 扩展信息 前两个字节是一个整数(不知道是不是词频) 后八个字节全是0
  29. #
  30. # {word_len,word,ext_len,ext} 一共重复same次 同音词 相同拼音表
  31.  
  32. # 拼音表偏移,
  33. startPy = 0x1540;
  34.  
  35. # 汉语词组表偏移
  36. startChinese = 0x2628;
  37.  
  38. # 全局拼音表
  39. GPy_Table = {}
  40.  
  41. # 解析结果
  42. # 元组(词频,拼音,中文词组)的列表
  43. GTable = []
  44.  
  45. # 原始字节码转为字符串
  46. def byte2str(data):
  47. pos = 0
  48. str = ''
  49. while pos < len(data):
  50. c = chr(struct.unpack('H', bytes([data[pos], data[pos + 1]]))[0])
  51. if c != chr(0):
  52. str += c
  53. pos += 2
  54. return str
  55.  
  56. # 获取拼音表
  57. def getPyTable(data):
  58. data = data[4:]
  59. pos = 0
  60. while pos < len(data):
  61. index = struct.unpack('H', bytes([data[pos], data[pos + 1]]))[0]
  62. pos += 2
  63. lenPy = struct.unpack('H', bytes([data[pos], data[pos + 1]]))[0]
  64. pos += 2
  65. py = byte2str(data[pos:pos + lenPy])
  66.  
  67. GPy_Table[index] = py
  68. pos += lenPy
  69.  
  70. # 获取一个词组的拼音
  71. def getWordPy(data):
  72. pos = 0
  73. ret = ''
  74. while pos < len(data):
  75. index = struct.unpack('H', bytes([data[pos], data[pos + 1]]))[0]
  76. ret += GPy_Table[index]
  77. pos += 2
  78. return ret
  79.  
  80. # 读取中文表
  81. def getChinese(data):
  82. pos = 0
  83. while pos < len(data):
  84. # 同音词数量
  85. same = struct.unpack('H', bytes([data[pos], data[pos + 1]]))[0]
  86.  
  87. # 拼音索引表长度
  88. pos += 2
  89. py_table_len = struct.unpack('H', bytes([data[pos], data[pos + 1]]))[0]
  90.  
  91. # 拼音索引表
  92. pos += 2
  93. py = getWordPy(data[pos: pos + py_table_len])
  94.  
  95. # 中文词组
  96. pos += py_table_len
  97. for i in range(same):
  98. # 中文词组长度
  99. c_len = struct.unpack('H', bytes([data[pos], data[pos + 1]]))[0]
  100. # 中文词组
  101. pos += 2
  102. word = byte2str(data[pos: pos + c_len])
  103. # 扩展数据长度
  104. pos += c_len
  105. ext_len = struct.unpack('H', bytes([data[pos], data[pos + 1]]))[0]
  106. # 词频
  107. pos += 2
  108. count = struct.unpack('H', bytes([data[pos], data[pos + 1]]))[0]
  109.  
  110. # 保存
  111. GTable.append((count, py, word))
  112.  
  113. # 到下个词的偏移位置
  114. pos += ext_len
  115.  
  116. def scel2txt(file_name):
  117. print('-' * 60)
  118. with open(file_name, 'rb') as f:
  119. data = f.read()
  120.  
  121. print("词库名:", byte2str(data[0x130:0x338])) # .encode('GB18030')
  122. print("词库类型:", byte2str(data[0x338:0x540]))
  123. print("描述信息:", byte2str(data[0x540:0xd40]))
  124. print("词库示例:", byte2str(data[0xd40:startPy]))
  125.  
  126. getPyTable(data[startPy:startChinese])
  127. getChinese(data[startChinese:])
  128.  
  129. def run(to_file, file=None, dir_path=None):
  130. """
  131. sel 多个文件转换
  132. :param file: sel文件路径 转换单个sel文件
  133. :param dir_path: sel文件夹路径 若设置 则转换该文件加内所有sel文件
  134. :param to_file: 转换完成文件路径
  135. :return:
  136. """
  137. if dir_path:
  138. fin = [fname for fname in os.listdir(in_path) if fname[-5:] == ".scel"]
  139. for f in fin:
  140. f = os.path.join(in_path, f)
  141. scel2txt(f)
  142. elif file:
  143. scel2txt(file)
  144. else:
  145. raise Exception('参数必须包含file或者dir_path')
  146. # 保存结果
  147. with open(to_file, 'w', encoding='utf8') as f:
  148. f.writelines([word + '\n' for count, py, word in GTable])
  149.  
  150. def dict_merge():
  151. """
  152. 词典合并
  153. :return:
  154. """
  155. with open('data/medical_dict.txt', encoding='utf8') as f:
  156. word_set1 = {word.strip() for word in f}
  157. with open('data/medical_dict2.txt', encoding='utf8') as f:
  158. word_set2 = {word.strip() for word in f}
  159. with open('data/medical_dict3.txt', encoding='utf8') as f:
  160. word_set3 = {word.strip() for word in f}
  161. word_set = word_set1 | word_set2 | word_set3
  162. with open('data/words_dict.txt', encoding='utf-8', mode='w') as f:
  163. for word in word_set:
  164. f.write(word + '\n')
  165.  
  166. if __name__ == '__main__':
  167. # run(file='data/细胞词库/医学词汇大全【官方推荐】.scel', to_file='医学词库.txt',)
  168. run(dir_path="data/细胞词库", to_file="data/cell_dict.txt")  

经验分享:直接拿来用。

常用函数二:refwork文件转换

refowrk是一种文献格式,可以用一些科研软件做分析使用,有些场景下我们需要将excel格式的文件转成refwork文件,一下代码可以实现这个功能。

  1. # -*- coding: utf-8 -*-
  2. """
  3. Datetime: 2020/03/04
  4. author: Zhang Yafei
  5. description: refwork格式转换
  6. 数据格式
  7. 列 RT,A1,T1,JF,YR,K1,AB,AD
  8. ...
  9. """
  10. import pandas as pd
  11.  
  12. def main(ref_file, to_file):
  13. """
  14. :param ref_file: 转换的csv或者excel文件路径
  15. :param to_file: 转换之后保存的refwork文件路径
  16. """
  17. if ref_file.endswith('csv'):
  18. rawdata = pd.read_csv(ref_file)
  19. elif ref_file.endswith('xls') or ref_file.endswith('xlsx'):
  20. rawdata = pd.read_excel(ref_file)
  21. with open(to_file, 'a') as f:
  22. for index, item in rawdata.iterrows():
  23. f.write('RT ' + item.RT)
  24. A1 = item.A1
  25. f.write('\n' + 'A1 ' + A1)
  26. T1 = item.T1
  27. f.write('\n' + 'T1 ' + T1)
  28. YR = item.YR
  29. f.write('\n' + 'YR ' + YR)
  30. JF = item.JF
  31. f.write('\n' + 'JF ' + JF)
  32. K1 = item.K1
  33. f.write('\n' + 'K1 ' + K1)
  34. AB = item.AB
  35. if pd.notna(AB):
  36. f.write('\n' + 'AB ' + AB)
  37. AD = item.AD
  38. if pd.notna(AD):
  39. f.write('\n' + 'AD ' + AD)
  40. f.write('\nDS CNKI')
  41. if index < rawdata.shape[0] - 1:
  42. f.write('\n\n\n')
  43.  
  44. if __name__ == '__main__':
  45. main(ref_file='data.xlsx', to_file='result.txt')

经验分享:直接拿来用

常用函数三:xml文档解析

xml文档经常作为数据传输格式在web领域使用,它有很多优势,但我们平时梳理的数据大多是csv或者exel这种,那么解析xml文档就是一个必备的技能吗,下面以pubmed下载的xml文档解析为例,展示了xml文档解析的整个流程。

  1. # -*- coding: utf-8 -*-
  2.  
  3. """
  4. @Datetime: 2019/4/26
  5. @Author: Zhang Yafei
  6. @Description: 07_xml文档解析
  7. """
  8. import os
  9. import re
  10. import threading
  11. from concurrent.futures import ThreadPoolExecutor
  12.  
  13. from lxml import etree
  14. import pandas as pd
  15.  
  16. def pubmed_xpath_parse(path):
  17. tree = etree.parse(path)
  18. # 如果xml数据中出现了关于dtd的声明(如下面的例子),那样的话,必须在使用lxml解析xml的时候,进行相应的声明。
  19. # parser = etree.XMLParser(load_dtd=True) # 首先根据dtd得到一个parser(注意dtd文件要放在和xml文件相同的目录)
  20. # tree = etree.parse('1.xml', parser=parser) # 用上面得到的parser将xml解析为树结构
  21. data_list = []
  22. pmid_set = []
  23. for articles in tree.xpath('//PubmedArticle'):
  24. pmid = articles.xpath('MedlineCitation/PMID/text()')[0]
  25. if pmid in pmid_set:
  26. continue
  27. pmid_set.append(pmid)
  28. Article = articles.xpath('MedlineCitation/Article')[0]
  29. journal = Article.xpath('Journal/ISOAbbreviation/text()')[0]
  30. try:
  31. authors = Article.xpath('AuthorList/Author')
  32. affiliations_info = set()
  33. for author in authors:
  34. # author_name = author.find('LastName').text + ' ' + author.find('ForeName').text
  35. affiliations = [x.xpath('Affiliation/text()')[0] for x in author.xpath('AffiliationInfo')]
  36. # author = author_name + ':' + ';'.join(affiliations)
  37. for affiliation in affiliations:
  38. affiliations_info.add(affiliation)
  39. affiliations_info = ';'.join(affiliations_info)
  40. except AttributeError:
  41. affiliations_info = ''
  42. try:
  43. date = Article.xpath('Journal/JournalIssue/PubDate/Year/text()')[0]
  44. except IndexError:
  45. date = Article.xpath('Journal/JournalIssue/PubDate/MedlineDate/text()')[0]
  46. date = re.search('\d+', date).group(0)
  47. try:
  48. mesh_words = []
  49. for mesh_heading in articles.xpath('MedlineCitation/MeshHeadingList/MeshHeading'):
  50. if len(mesh_heading.xpath('child::*')) == 1:
  51. mesh_words.append((mesh_heading.xpath('child::*'))[0].text)
  52. continue
  53. mesh_name = ''
  54. for mesh in mesh_heading.xpath('child::*'):
  55. if mesh.tag == 'DescriptorName':
  56. mesh_name = mesh.xpath('string()')
  57. continue
  58. if mesh_name and mesh.tag == 'QualifierName':
  59. mesh_word = mesh_name + '/' + mesh.xpath('string()')
  60. mesh_words.append(mesh_word)
  61. mesh_words = ';'.join(mesh_words)
  62. except AttributeError:
  63. mesh_words = ''
  64. article_type = '/'.join([x.xpath('./text()')[0] for x in Article.xpath('PublicationTypeList/PublicationType')])
  65. country = articles.xpath('MedlineCitation/MedlineJournalInfo/Country/text()')[0]
  66. data_list.append(
  67. {'PMID': pmid, 'journal': journal, 'affiliations_info': affiliations_info, 'pub_year': date,
  68. 'mesh_words': mesh_words,
  69. 'country': country, 'article_type': article_type, 'file_path': path})
  70. print(pmid + '\t解析完成')
  71. df = pd.DataFrame(data_list)
  72. with threading.Lock():
  73. df.to_csv('pubmed.csv', encoding='utf_8_sig', mode='a', index=False, header=False)
  74.  
  75. def to_excel(data, path):
  76. writer = pd.ExcelWriter(path)
  77. data.to_excel(writer, sheet_name='table', index=False)
  78. writer.save()
  79.  
  80. def get_files_path(dir_name):
  81. xml_files = []
  82. for base_path, folders, files in os.walk(dir_name):
  83. xml_files = xml_files + [os.path.join(base_path, file) for file in files if file.endswith('.xml')]
  84. return xml_files
  85.  
  86. if __name__ == '__main__':
  87. files = get_files_path(dir_name='data')
  88. if not files:
  89. print('全部解析完成')
  90. else:
  91. with ThreadPoolExecutor() as pool:
  92. pool.map(pubmed_xpath_parse, files)

常用函数四:文本分词

方式一:jieba分词+停用词+自定义词典+同义词替换

  1. # -*- coding: utf-8 -*-
  2.  
  3. """
  4. Datetime: 2020/06/25
  5. Author: Zhang Yafei
  6. Description: 文本分词
  7. 输入 停用词文件路径 词典文件路径 同义词文件路径 分词文件路径 表名(可选) 列名 分词结果列名 保存文件名
  8. 输出 分词结果-文件
  9. """
  10. import os
  11. import re
  12. import time
  13. from collections import defaultdict
  14. from functools import wraps
  15.  
  16. import jieba
  17. import pandas as pd
  18.  
  19. if not os.path.exists('res'):
  20. os.mkdir('res')
  21.  
  22. def timeit(func):
  23. """ 时间装饰器 """
  24.  
  25. @wraps(func)
  26. def inner(*args, **kwargs):
  27. start_time = time.time()
  28. ret = func(*args, **kwargs)
  29. end_time = time.time() - start_time
  30. if end_time < 60:
  31. print(f'共花费时间:', round(end_time, 2), '秒')
  32. else:
  33. minute, sec = divmod(end_time, 60)
  34. print(f'花费时间\t{round(minute)}分\t{round(sec, 2)}秒')
  35. return ret
  36.  
  37. return inner
  38.  
  39. class TextCut(object):
  40. def __init__(self, dictionary=None, stopwords=None, synword=None):
  41. self.dictionary = dictionary
  42. self.word_list = None
  43. if self.dictionary:
  44. jieba.load_userdict(self.dictionary)
  45. if stopwords:
  46. with open(stopwords, 'r', encoding='utf-8') as swf:
  47. self.stopwords = [line.strip() for line in swf]
  48. else:
  49. self.stopwords = None
  50. if synword:
  51. self.syn_word_dict = self.build_sync_dict(synword)
  52. else:
  53. self.syn_word_dict = None
  54.  
  55. @staticmethod
  56. def clean_txt(raw):
  57. file = re.compile(r"[^0-9a-zA-Z\u4e00-\u9fa5]+")
  58. return file.sub(' ', raw)
  59.  
  60. def cut(self, text):
  61. sentence = self.clean_txt(text.strip().replace('\n', ''))
  62. return ' '.join([i for i in jieba.cut(sentence) if i.strip() and i not in self.stopwords and len(i) > 1])
  63.  
  64. def cut2(self, text):
  65. sentence = self.clean_txt(text.strip().replace('\n', ''))
  66. return ' '.join([i for i in jieba.cut(sentence) if
  67. i.strip() and i not in self.stopwords and len(i) > 1 and i in self.word_list])
  68.  
  69. def syn_word_replace(self, row):
  70. word_list = []
  71. for word in row.split(' '):
  72. if word in self.syn_word_dict:
  73. word = self.syn_word_dict[word]
  74. word_list.append(word)
  75. return ' '.join(word_list)
  76.  
  77. def build_sync_dict(self, synword):
  78. syn_map = {}
  79. with open(synword, mode='r', encoding='utf-8') as f:
  80. for row in f:
  81. stand_word = row.split(',')[0].strip()
  82. for word in row.split(',')[1:]:
  83. if word.strip():
  84. syn_map[word.strip()] = stand_word
  85. return syn_map
  86.  
  87. @timeit
  88. def run(self, file_path, col_name, new_col_name, to_file, sheet_name=None, word_in_dict=False):
  89. print('######### 开始读取数据文件 ############')
  90. if sheet_name:
  91. df = pd.read_excel(file_path, sheet_name=sheet_name)
  92. else:
  93. df = pd.read_excel(file_path)
  94. print('######### 开始进行数据处理 ############')
  95. if word_in_dict:
  96. with open(self.dictionary, encoding='utf-8') as f:
  97. self.word_list = [word.strip() for word in f]
  98. df[new_col_name] = df[col_name].apply(self.cut2)
  99. else:
  100. df[new_col_name] = df[col_name].apply(self.cut)
  101.  
  102. if self.syn_word_dict:
  103. print('######### 正在进行同义词合并 ############')
  104. df[f'{new_col_name}_同义词替换'] = df[new_col_name].apply(self.syn_word_replace)
  105. print('######### 同义词合并完成 ############')
  106. df.to_excel(to_file, index=False)
  107. print('######### 处理完成 ############')
  108.  
  109. if __name__ == "__main__":
  110. text_cut = TextCut(stopwords='data/stopwords.txt', dictionary='data/word_dict.txt', synword='data/同义词.txt')
  111. text_cut.run(file_path='data/山西政策.xlsx', sheet_name='1.21-2.20', col_name='全文', new_col_name='全文分词',
  112. to_file='res/山西政策_分词.xlsx')
  113. # text_cut.run(file_path='data/微博数据_处理.xlsx', col_name='微博正文_处理', new_col_name='全文分词',
  114. # to_file='data/微博分词.xlsx')

方式二:jieba分词+信息熵合并

  1. # -*- coding: utf-8 -*-
  2.  
  3. """
  4. Datetime: 2020/03/01
  5. Author: Zhang Yafei
  6. Description: 基于信息熵对分词结果进行合并
  7. """
  8. from collections import Counter
  9. from functools import reduce
  10. from pandas import read_excel, DataFrame
  11.  
  12. class InfoEntropyMerge(object):
  13. def __init__(self, data, stopwords='data/stopwords.txt'):
  14. self.data = data
  15. self.words_freq_one = {}
  16. self.words_freq_two = {}
  17. self.entropy_words_dict = {}
  18. if stopwords:
  19. with open(stopwords, 'r', encoding='utf-8') as f:
  20. self.stopwords = {line.strip() for line in f}
  21. else:
  22. self.stopwords = None
  23.  
  24. def count_word_freq_one(self, save_to_file=False, word_freq_file=None):
  25. keywords = (word for word_list in self.data for word in word_list if word)
  26. self.words_freq_one = Counter(keywords)
  27. if save_to_file:
  28. words = [word for word in self.words_freq_one]
  29. freqs = [self.words_freq_one[word] for word in words]
  30. words_df = DataFrame(data={'word': words, 'freq': freqs})
  31. words_df.sort_values('freq', ascending=False, inplace=True)
  32. words_df.to_excel(word_freq_file, index=False)
  33.  
  34. def count_freq(self, word1, word2):
  35. """
  36. 统计相邻两个词出现的频率
  37. :param word1:
  38. :param word2:
  39. :return:
  40. """
  41. if (word1, word2) not in self.words_freq_two:
  42. self.words_freq_two[(word1, word2)] = 1
  43. else:
  44. self.words_freq_two[(word1, word2)] += 1
  45. return word2
  46.  
  47. def count_word_freq_two(self, save_to_file=False, word_freq_file=None):
  48. """
  49. 计算相邻两个词出现的频率
  50. :param save_to_file:
  51. :param word_freq_file:
  52. :return:
  53. """
  54. for word_list in self.data:
  55. reduce(self.count_freq, word_list)
  56. if save_to_file and word_freq_file:
  57. words_list = [(word1, word2) for word1, word2 in self.words_freq_two]
  58. freqs = [self.words_freq_two[w1_w2] for w1_w2 in words_list]
  59. words_df = DataFrame(data={'word': words_list, 'freq': freqs})
  60. words_df.sort_values('freq', ascending=False, inplace=True)
  61. words_df.to_excel(word_freq_file, index=False)
  62.  
  63. @staticmethod
  64. def is_chinese(word):
  65. for ch in word:
  66. if '\u4e00' <= ch <= '\u9fff':
  67. return True
  68. return False
  69.  
  70. def clac_entropy(self, save_to_file=False, dict_path='data/entropy_dict.txt'):
  71. """
  72. 计算信息熵: E(w1, w2) = P(w1,w2)/min(P(w1),P(w2))
  73. :param save_to_file: 是否将熵值大于0.5的新词保存到文件中
  74. :param dict_path: 保存字典路径
  75. :return:
  76. """
  77. for word1, word2 in self.words_freq_two:
  78. freq_two = self.words_freq_two[(word1, word2)]
  79. freq_one_min = min(self.words_freq_one[word1], self.words_freq_one[word2])
  80. freq_one_max = max(self.words_freq_one[word1], self.words_freq_one[word2])
  81. w1_w2_entropy = freq_two / freq_one_max
  82. if self.stopwords:
  83. if w1_w2_entropy > 0.5 and word1 not in self.stopwords and word2 not in self.stopwords and self.is_chinese(word1) and self.is_chinese(word2):
  84. # print(word1, word2, freq_two, freq_one_min, freq_one_max)
  85. self.entropy_words_dict[word1+word2] = w1_w2_entropy
  86. else:
  87. if w1_w2_entropy > 0.5:
  88. self.entropy_words_dict[word1+word2] = w1_w2_entropy
  89.  
  90. print('信息熵大于0.5的词语组合:\n', self.entropy_words_dict)
  91. if save_to_file and dict_path:
  92. with open(dict_path, mode='r+', encoding='utf-8') as f:
  93. content = f.read()
  94. f.seek(0, 0)
  95. for word in self.entropy_words_dict:
  96. f.write(word+'\n')
  97. f.write(content)
  98. print(f'成功将信息熵大于0.5的词语保存到了{dict_path}中')
  99.  
  100. def data_read(path, col_name):
  101. df = read_excel(path)
  102. texts = df.loc[df[col_name].notna(), col_name].str.split()
  103. return texts
  104.  
  105. if __name__ == '__main__':
  106. text_list = data_read(path='res/国家政策_分词.xlsx', col_name='全文分词')
  107. info_entro = InfoEntropyMerge(data=text_list)
  108. info_entro.count_word_freq_one()
  109. info_entro.count_word_freq_two()
  110. info_entro.clac_entropy(save_to_file=False, dict_path='data/entropy_dict.txt')

经验分享:若有好的词典和停用词,优先选用方式一,否则选择方式二。

Python常用功能函数系列总结(二)的更多相关文章

  1. Python常用功能函数系列总结(一)

    本节目录 常用函数一:获取指定文件夹内所有文件 常用函数二:文件合并 常用函数三:将文件按时间划分 常用函数四:数据去重 写在前面 写代码也有很长时间了,总觉得应该做点什么有价值的事情,写代码初始阶段 ...

  2. Python常用功能函数系列总结(三)

    本节目录 常用函数一:词频统计 常用函数二:word2vec 常用函数三:doc2vec 常用函数四:LDA主题分析 常用函数一:词频统计 # -*- coding: utf-8 -*- " ...

  3. Python常用功能函数系列总结(六)

    本节目录 常用函数一:词云图 常用函数二:关键词清洗 常用函数三:中英文姓名转换  常用函数四:去除文本中的HTML标签和文本清洗 常用函数一:词云图 wordcloud # -*- coding: ...

  4. Python常用功能函数系列总结(五)

    本节目录 常用函数一:向量距离和相似度计算 常用函数二:pagerank 常用函数三:TF-IDF 常用函数四:关键词提取 常用函数一:向量距离和相似度计算 KL距离.JS距离.余弦距离 # -*- ...

  5. Python常用功能函数系列总结(四)之数据库操作

    本节目录 常用函数一:redis操作 常用函数二:mongodb操作 常用函数三:数据库连接池操作 常用函数四:pandas连接数据库 常用函数五:异步连接数据库 常用函数一:redis操作 # -* ...

  6. Python常用功能函数系列总结(七)

    本节目录 常用函数一:批量文件重命名 常用函数一:批量文件重命名 # -*- coding: utf-8 -*- """ DateTime : 2021/02/08 10 ...

  7. Python常用功能函数总结系列

    Python常用功能函数系列总结(一) 常用函数一:获取指定文件夹内所有文件 常用函数二:文件合并 常用函数三:将文件按时间划分 常用函数四:数据去重 Python常用功能函数系列总结(二) 常用函数 ...

  8. Python常用功能函数

    Python常用功能函数汇总 1.按行写字符串到文件中 import sys, os, time, json def saveContext(filename,*name): format = '^' ...

  9. Python 常用string函数

    Python 常用string函数 字符串中字符大小写的变换 1. str.lower()   //小写>>> 'SkatE'.lower()'skate' 2. str.upper ...

随机推荐

  1. 『与善仁』Appium基础 — 21、元素的基本操作

    目录 1.元素的基本操作说明 (1)点击操作 (2)清空操作 (3)输入操作 2.综合练习 1.元素的基本操作说明 (1)点击操作 点击操作:click()方法.(同Selenium中使用方式一致) ...

  2. centos7源码安装Nginx-1.6

    目录 一.环境介绍 二.安装 三.使用验证 四.附录 编译参数详解 一.环境介绍 nginx的版本功能相差不大,具体支持可以查看官网的功能列表 环境信息: [nginx-server] 主机名:hos ...

  3. rpm-build方式制作rpm包

    目录 一.简介 二.具体操作 一.简介 可以将编译完成的服务打成rpm包放到私有仓库了,用于自定义的各种软件进行安装部署配置. 二.具体操作 1.安装软件,这个命令将构建rpm包 yum -y ins ...

  4. Excel如何使用vlookup

    一.vlookup的语法 VLOOKUP (lookup_value, table_array, col_index_num, [range_lookup]) ①Lookup_value为需要在数据表 ...

  5. heap exploit about ptmalloc in glibc version 2.31

    学习的一下高版本的libc的利用方式. 项目地址:https://github.com/StarCross-Tech/heap_exploit_2.31 tcache_dup 源代码: 1 #incl ...

  6. 数据库函数(Excel函数集团)

    此处文章均为本妖原创,供下载.学习.探讨! 文章下载源是Office365国内版1Driver,如有链接问题请联系我. 请勿用于商业! 谢谢 下载地址:https://officecommunity- ...

  7. 小迪安全 Web安全 基础入门 - 第八天 - 信息打点-系统篇&端口扫描&CDN服务&负载均衡&WAF防火墙

    一.获取网络信息-服务厂商&网络架构 1.通过whois查询获取. 2.nmap.goby等扫描工具扫描获取. 3.https://www.netcraft.com/等网站查询获取. 二.服务 ...

  8. java 图形化小工具Abstract Window Toolit 菜单项

    AWT 中的菜单由如下几个类组合而成 MenuBar: 菜单条,菜单的容器. Menu: 菜单组件,菜单项的容器,它也是Menultem的子类,所以可作为菜单项使用. PopupMenu: 上下文菜单 ...

  9. Java 数据类型:集合接口Map:HashTable;HashMap;IdentityHashMap;LinkedHashMap;Properties类读取配置文件;SortedMap接口和TreeMap实现类:【线程安全的ConcurrentHashMap】

    Map集合java.util.Map Map用于保存具有映射关系的数据,因此Map集合里保存着两个值,一个是用于保存Map里的key,另外一组值用于保存Map里的value.key和value都可以是 ...

  10. AcWing1264. 动态求连续区间和 (树状数组做法)

    1.题目 给定 n 个数组成的一个数列,规定有两种操作,一是修改某个元素,二是求子数列 [a,b] 的连续和. 输入格式 第一行包含两个整数 n 和 m,分别表示数的个数和操作次数. 第二行包含 n ...