正则表达式(R&Python)
regular expression
1.R,strongly recommend this blog
The table_info examples are following:
du_mtime_cinema_showtime20190606
du_amap_shoppingmall_indoor_201903_d4
du_amap_shopping_mall_info_2017
du_amap_ship_201909
I want tables which start with"du_amap_" and end with year/month, so in the tables above,
I only want the fourth one. Below, in R, character escape (the backlash character \) should be \\.
"^"means the start and "$" means the end.
^can delete but $ can't because we use "grep" function.
keyword_all <-'^du_amap_.+2\\d{5}$'
keyword_table <- grep(keyword_all, table_info$Tables_in_risingdata, value =T)
str_extract_all is a function which only filters out the characters that fits the pattern.
The below codes extract the last six numbers:year and month
table_name_body <- 'amap_cvs_citycount'
month<-str_extract_all(string=keyword_table[p],pattern='\\d.+')%>% as.character()
* means the pattern in front of it will appear one or more times, | means or, and . means any characters.
Below codes means deleting "du_amap_" and "_201..".
keyword <- gsub('.*amap_|_201.*', '', table_name_body)
shoppingmall_amap$name<-gsub('(\\(.*\\))',"",shoppingmall_amap$name)
latitude and longtitude
\\d{2}[.]\\d+
find Chinese
[\u4E00-\u9FA5\\s]+ #many characters,including space
[\u4E00-\u9FA5]+ #many characters,not including space
[\u4E00-\u9FA5] #one character
2.Python
包
import re
查找数字,注意这里python转义只有一个\,但R里转义要两个:\\
pattern1 = re.compile(r'\d+')
这里是找表格里每行以(080)开头的数字
pattern1 = re.compile(r'\(080\)\d+')
fixed_line_all=pd.DataFrame()
for i in range(len(calls_pd[0])):
fixed_line=pattern1.findall(calls_pd[0][i])
fixed_line_all=set(fixed_line_all).union(fixed_line)
fixed_line_all=pd.DataFrame(fixed_line_all)
这里提取以7、8、9开头的前四位数
pattern2=re.compile(r'^(7\d{3}|8\d{3}|9\d{3})')
for i in range(len(fixed_line_bind[1])):
mobile_line=pattern2.findall(fixed_line_bind[1][i])
mobile_bang=set(mobile_bang).union(mobile_line)
mobile_bang=pd.DataFrame(mobile_bang)
正则表达式(R&Python)的更多相关文章
- 正则表达式与Python中re模块的使用
正则表达式与Python中re模块的使用 最近做了点爬虫,正则表达式使用的非常多,用Python做的话会用到re模块. 本文总结一下正则表达式与re模块的基础与使用. 另外,给大家介绍一个在线测试正则 ...
- python全栈开发之正则表达式和python的re模块
正则表达式和python的re模块 python全栈开发,正则表达式,re模块 一 正则表达式 正则表达式(Regular Expression)是一种文本模式,包括普通字符(例如,a 到 z 之间的 ...
- (转)正则表达式与Python(RE)模块
Python正则表达式指南 原文:http://blog.csdn.net/qdx411324962/article/details/46799831 Python3(2):正则表达式与Python ...
- 正则表达式r和re
# coding:utf-8 import re print 'a\ws' print r'a\nb' # r'': 一般用在正则表达式中,称为原始字符串,作用是将Python语法中的反斜杠转义给 取 ...
- 一句python,一句R︱python中的字符串操作、中文乱码、NaN情况
一句python,一句R︱python中的字符串操作.中文乱码.NaN情况 先学了R,最近刚刚上手Python,所以想着将python和R结合起来互相对比来更好理解python.最好就是一句pytho ...
- A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python)
A Complete Tutorial on Tree Based Modeling from Scratch (in R & Python) MACHINE LEARNING PYTHON ...
- 7 Tools for Data Visualization in R, Python, and Julia
7 Tools for Data Visualization in R, Python, and Julia Last week, some examples of creating visualiz ...
- NLP︱高级词向量表达(一)——GloVe(理论、相关测评结果、R&python实现、相关应用)
有很多改进版的word2vec,但是目前还是word2vec最流行,但是Glove也有很多在提及,笔者在自己实验的时候,发现Glove也还是有很多优点以及可以深入研究对比的地方的,所以对其进行了一定的 ...
- 数据科学实战手册(R+Python)书中引用资料网址
本文会持续将<数据科学实战手册(R+Python)>一书中的附带参考资料网址手打出来, 方便访问. 由于书中的参考资料网址太多, 这个文档将可能花费一段时间才能完成. 第一章 P7 Rs ...
- 常用正则表达式与python中的re模块
正则表达式是一种通用的字符串匹配技术,不会因为编程语言不一样而发生变化. 部分常用正则表达式规则介绍: . 匹配任意的一个字符串,除了\n * 匹配任意字符串0次或者任意次 \w 匹配字母.数字.下划 ...
随机推荐
- FPGA小白学习之路(5)clk为什么要用posedge,而不用negedge(转)
clk为什么要用posedge,而不用negedge 转自:http://www.cnblogs.com/dangxia/archive/2012/03/07/2383744.html Verilog ...
- 并查集(不相交集)的Remove操作
给并查集(不相交集)的添加一个\(Remove(X)\)操作,该操作把\(X\)从当前的集合中除去并把它放到自己的集合中. 实现思想 英文原句 We assume that the tree is i ...
- 沪江iKcamp出品微信小程序教学共5章16小节汇总(含视频)
- 37个JavaScript基本面试问题和解答
1.使用typeof bar ==="object"来确定bar是否是一个对象时有什么潜在的缺陷?这个陷阱如何避免? 尽管typeof bar ==="object&qu ...
- JZOJ 1775. 合并果子2 (Standard IO)
1775. 合并果子2 (Standard IO) Time Limits: 1000 ms Memory Limits: 65536 KB Description 在一个果园里,多多已经将所有的果子 ...
- Yuchuan_linux_C 编程之八 文件操作相关函数
一.整体大纲 st_mode整体介绍: st_mode详细介绍: 二. Linux文件操作相关函数 1. stat 作用:获得文件信息,也可以获取文件大小. 头文件 #include <sys/ ...
- AOP和spring AOP学习记录
AOP基本概念的理解 面向切面AOP主要是在编译期或运行时,对程序进行织入,实现代理, 对原代码毫无侵入性,不破坏主要业务逻辑,减少程序的耦合度. 主要应用范围: 日志记录,性能统计,安全控制,事务处 ...
- python使用for循环打印9*9乘法表。
代码如下: for a in range(1, 10): for b in range(1, 10): if b <= a: print("%d*%d=%d\t" % (b, ...
- 基于Canal和Kafka实现MySQL的Binlog近实时同步
前提 近段时间,业务系统架构基本完备,数据层面的建设比较薄弱,因为笔者目前工作重心在于搭建一个小型的数据平台.优先级比较高的一个任务就是需要近实时同步业务系统的数据(包括保存.更新或者软删除)到一个另 ...
- 用shell脚本实现定时备份数据库
1.备份数据库的方法 可以使用命令查看 ls /usr/local/mysql/bin 这个mysqldump就是系统内置的用来备份数据库的工具. 2.实现方法 ①先随便进入一个位置创建一个目录 ② ...