正则表达式(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 匹配字母.数字.下划 ...
随机推荐
- [置顶]
利用Python 提醒实验室同学值日(自动发送邮件)
前言: 在实验室里一直存在着一个问题,就是老是有人忘记提醒下一个人值日,然后值日就被迫中断了.毕竟良好的 卫生环境需要大家一起来维护的!没办法只能想出一些小对策了. 解决思路: 首先,我 ...
- 大多数项目中会用到的webpack小技巧
原文地址 本文是作者对自己所学的webpack技巧的总结,在没有指定特殊情况下适用于webpack 3.0版本. 进度汇报 使用webpack --progress --colors这样可以让编译的输 ...
- TensorFlow CPU环境 SSE/AVX/FMA 指令集编译
TensorFlow CPU环境 SSE/AVX/FMA 指令集编译 sess.run()出现如下Warning W tensorflow/core/platform/cpu_feature_guar ...
- Nacos 数据持久化 mysql8.0
一.问题描述 直接下载的稳定版本nacos编译后的文件,不支持mysql8及其以上版本,按照官网文档:https://nacos.io/zh-cn/docs/deployment.html 执行完成之 ...
- Java基础 - Date的相关使用(获取系统当前时间)
前言: 在日常Java开发中,常常会使用到Date的相关操作,如:获取当前系统时间.获取当前时间戳.时间戳按指定格式转换成时间等.以前用到的时候,大部分是去网上找,但事后又很快忘记.现为方便自己今后查 ...
- 用python实现LBP特征点计算
import cv2 import numpy as np def olbp(src): dst = np.zeros(src.shape,dtype=src.dtype) for i in rang ...
- C++ 判断两个圆是否有交集
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include <math.h> #include <easyx.h ...
- vue的$message(提示框换行)
之前一直在搜怎么让提示框的文字换行,网上搜到的基本都是使用 ‘ /n ’,使用无效,也试了css换行,本来想用弹窗自己编辑html内容,还好回去官网看了一下: let arr = ['测试一', '测 ...
- Asp.Net Core 中IdentityServer4 授权原理及刷新Token的应用
一.前言 上面分享了IdentityServer4 两篇系列文章,核心主题主要是密码授权模式及自定义授权模式,但是仅仅是分享了这两种模式的使用,这篇文章进一步来分享IdentityServer4的授权 ...
- ffmpeg 使用
ffmpeg 使用 一.介绍 FFmpeg 是视频处理最常用的开源软件,大量用于视频网站和商业软件(比如 Youtube 和 iTunes),视频本身是一个容器,里面包含了视频.音频和字幕等.FFmp ...