通过使用python来清洗数据的技巧持续更新:【内向即失败--王奕君】
来源:互联网 发布:基站定位软件 编辑:程序博客网 时间:2024/06/06 00:33
# - * - coding:utf8 -import stringimport redef clean_html(text:'str'): '''html解码''' text = text.replace('&', '&') text = text.replace('<', '<') text = text.replace('>', '>') text = text.replace(' ', '') text = text.replace(''', "\'") text = text.replace('"', '\"') text = text.replace('<br>;', '\n') return textdef clean_space(text:'str'): '''去掉\r\n以及空格''' text = text.replace('\r', '') text = text.replace('\n', '') text=text.replace(' ','') return textdef clean_symbol(text:'str'): '''去掉所有符号''' return re.sub("[\.\!\/_,$%^*(+\"\']+|[+—!,。?、~@#¥%…&*()]+", "", text)def clean_bothnumber(text:'str'): '''去掉两边数字''' return text.strip(string.digits)def clean_listspace(tabulation:'object()'): '''去掉列表\r\n以及空格 最终返回列表 ''' if isinstance(tabulation,(list)): transform_tabulation=str(tabulation) text = transform_tabulation.replace('\r', '') text = transform_tabulation.replace('\n', '') text=transform_tabulation.replace(' ','') return eval(text) elif isinstance(tabulation,(str)): text = tabulation.replace('\r', '') text = tabulation.replace('\n', '') text = tabulation.replace(' ', '') return eval(text)def clean_bothsymbol(text:'str'): '''去掉两边的所有符号''' return text.strip(string.punctuation)def clean_custom(text:'str',container:'list'): '''去掉自定义文本''' for con in container: text=text.replace(con,'') return textdef clean_script(text:'str'): '''去除html脚本''' return re.compile(r'<script.*?</script>',re.I | re.S).sub('',text)def clean_rapecode(text:'str'): '''去掉html注释''' return re.compile(r'<!.*?>', re.I | re.S).sub('',text)def clean_htmlcode(text:'str'): '''去掉html标签''' return re.compile(r'<.*?/{0,1}>',re.I).sub('',text)def clean_englishsymbol(text:'str'): '''去掉英文前后所有的英文符号'''
阅读全文
0 0
- 通过使用python来清洗数据的技巧持续更新:【内向即失败--王奕君】
- 通过使用python来转化数据的技巧持续更新:【内向即失败--王奕君】
- 通过使用python来处理数据的技巧持续更新:【内向即失败--王奕君】
- 通过使用python来处理文件的技巧持续更新:【内向即失败--王奕君】
- 通过使用python来处理网络的技巧持续更新:【内向即失败--王奕君】
- 通过使用python来写下载器的技巧持续更新:【内向即失败--王奕君】
- 伪知识之了解python中_init_.py的含义及作用持续更新:【内向即失败--王奕君】
- 语料库之车品牌持续更新:【内向即失败--王奕君】
- 语料库之敏感词持续更新:【内向即失败--王奕君】
- 语料库之大学名持续更新:【内向即失败--王奕君】
- 语料库之专业名持续更新:【内向即失败--王奕君】
- 语料库之常用字持续更新:【内向即失败--王奕君】
- 语料库之职业名持续更新:【内向即失败--王奕君】
- python工具代码之身份证校验持续更新:【内向即失败--王奕君】
- 伪知识之了解数据库中回滚操作的含义持续更新:【内向即失败--王奕君】
- 伪知识之通俗易懂得解释计算机系统的专有名词持续更新:【内向即失败--王奕君】
- python伪代码之爬取全国高校历年分数线运行代码持续更新:【内向即失败--王奕君】
- python伪代码之爬取全国高校专业人气榜运行代码持续更新:【内向即失败--王奕君】
- udp广播
- MACOS平台上的MyEclipse2016安装tomcat及一些问题解决
- 通过使用python来处理网络的技巧持续更新:【内向即失败--王奕君】
- Android jni开发-2(在旧项目上添加支持cmake编译的jni)
- 通过使用python来处理数据的技巧持续更新:【内向即失败--王奕君】
- 通过使用python来清洗数据的技巧持续更新:【内向即失败--王奕君】
- 通过使用python来写下载器的技巧持续更新:【内向即失败--王奕君】
- ubuntu安装mysql不能远程访问的大坑
- 安卓 设置页面为URL地址
- 171207 逆向-JarvisOJ(病毒数据分析)(2)
- 语料库之车品牌持续更新:【内向即失败--王奕君】
- 语料库之敏感词持续更新:【内向即失败--王奕君】
- 台大-林轩田老师-机器学习基石学习笔记11
- socket的TIME_WAIT状态的原因及解决办法和避免的办法