match

R partial match in data frame

淺唱寂寞╮ 提交于 2020-01-04 09:04:41
问题 How can I address a partial match in a data frame? Lets say this is my df df V1 V2 V3 V4 1 ABC 1.2 4.3 A 2 CFS 2.3 1.7 A 3 dgf 1.3 4.4 A and I want to add a column V5 containing a number 111 only if the value in V1 contains a "f" in the name and a number 222 only if the value in V1 contains a "gf". Will I get problems since several values contain an "f" - or does the order I ender the commands will take care of it? I tried something like: df$V5<- ifelse(df$V1 = c("*f","*gf"),c=(111,222) ) but

react-router match query string

橙三吉。 提交于 2020-01-03 16:49:41
问题 https://github.com/reactjs/react-router/example I tried the example on npm start query string match to route is not working on the example. When I click the second one, It's activating wrong one http://localhost:8080/query-params/user/bob?showAge=1 and refreshing on the link above not matching any routes. Even if I have change the example code to below <Route path="user/:userID(?:showAge)" component={User} /> I tried couple of things that might work based on docs but none of them worked. Am I

Orchard之创建列表

佐手、 提交于 2020-01-03 10:27:09
一:首先需要确保 List Module 的开始 即: Enable 之后,左边的列表中,多了一个 List 功能菜单。 二:为 Content type 选定 Cotainable 不再赘述。 三:创建 List 四:为 List 添加 Item 注意,一定要在 List 处添加 Item,如下: 如果我们在 New 处直接添加 Item 本身,则不会出现在列表中,如下: 五:最终效果 六:自定义列表显式 现在,我们并不需要显式那么多的内容在列表中,这个时候,就需要我们改写 Placement.info 这个文件,如下: 在这里,几乎每一行都有自己的意义,现在一一指出: <Match ContentType="Event"> 这里我们的 ContentType 的 ID,不是 DispalyName <Match DisplayType="Detail"> 定义详细显式时候的内容 <Place Parts_Common_Body="Content:1"/> </Match> <Match DisplayType="Summary"> 定义概要显式时候的内容(如:列表) <Place Parts_Comments_Count="Nowhere" 不显式评论信息 Parts_Common_Metadata_Summary="Nowhere" 不显式标题和发表时间等元数据信息

Regex to find id in url

点点圈 提交于 2020-01-03 08:50:11
问题 I have the following URL: http://example.com/product/1/something/another-thing Although it can also be: http://test.example.com/product/1/something/another-thing or http://completelydifferentdomain.tdl/product/1/something/another-thing And I want to get the number 1 (id) from the URL using Javascript. The only thing that would always be the same is /product . But I have some other pages where there is also /product in the url just not at the start of the path. What would the regex look like?

Number of Matches Between Two Comma Separated Factors in a Data Frame

天大地大妈咪最大 提交于 2020-01-03 05:10:10
问题 I have a dataframe that looks something like this: Row ID1 ID2 Colors1 Colors2 1 1 2 Green, Blue Red, Orange 2 1 3 Green, Orange Orange, Red I would like to create a calculation that tells me the count of colors in common between Colors1 and Colors2. The desired result is the following: Row ID1 ID2 Colors1 Colors2 Common 1 1 2 Green, Blue, Purple Green, Purple 2 #Green, Purple 2 1 3 Green, Orange Orange, Red 1 #Orange 回答1: You can use: col1 <- strsplit(df$Colors1, ", ") col2 <- strsplit(df

Python网络爬虫与信息提取

妖精的绣舞 提交于 2020-01-03 04:25:13
1.Requests库入门 Requests安装 用管理员身份打开命令提示符: pip install requests 测试:打开IDLE: >>> import requests >>> r = requests.get("http://www.baidu.com") >>> r.status_code 200 >>> r.encoding = 'utf-8' #修改默认编码 >>> r.text #打印网页内容 HTTP协议 超文本传输协议,Hypertext Transfer Protocol. HTTP是一个基于“请求与响应”模式的、无状态的应用层协议。 HTTP协议采用URL作为定位网络资源的标识。 URL格式 http://host[:port][path] host:合法的Internet主机域名或IP地址 port:端口号,缺省端口为80 path:请求资源的路径 操作 方法 说明 GET 请求获取URL位置的资源 HEAD 请求获取URl位置资源的响应消息报告,即获得该资源的头部信息 POST 请求向URL位置的资源后附加新的数据 PUT 请求向URL位置存储一个资源,覆盖原URL位置的资源 PATCH 请求局部更新URL位置的资源,即改变该处资源的部分内容 DELETE 请求删除URL位置存储的资源 Requests主要方法 方法 说明 requests

爬虫系列之豆瓣图书排行

為{幸葍}努か 提交于 2020-01-03 04:15:18
豆瓣上有图书的排行榜,所以这次写了一个豆瓣的爬虫。 首先是分析排行榜的url 根据这个可以很容易的知道不同图书的排行榜就是在网站后面加上/tag/【类别】,所以我们首先要获得图书的类别信息。 这里可以将读书首页的热门标签给爬下来。 爬取标签内容并不难,代码如下: 1 def getLabel(url): #获得热门标签 2 html = getHTMLText(url) 3 soup = BeautifulSoup(html, 'html.parser') 4 a = soup.find_all('a') 5 label_list = [] 6 for i in a: 7 try: 8 href = i.attrs['href'] 9 match = re.search(r'/tag/.*', href) 10 if match and match[0][5]!='?': 11 label_list.append(match[0]) 12 except: 13 continue 14 return label_list 接下来是进入排行榜页面进行信息爬取, 代码如下: 1 def getBookInfo(): 2 label_list = getLabel('https://book.douban.com/') 3 label = get_label(label_list) 4

Excel Find the largest partial value in an indexed list

[亡魂溺海] 提交于 2020-01-03 02:54:13
问题 I am working with excel and trying to find if a portion of one cell matches anything from a list. I am attempting to extract that part of the cell as my result. The formula I am working with is: {=INDEX($A$1:$A$10,MATCH(1,COUNTIF(B1,"* "&$A$1:$A$10&"*"),0))} note: had to space out the asterisk to avoid italics A1 to A10 is the list i am referencing and anything in column B is what I am searching partail parts for in the list The problem is the formula return the most common value found in the

Regular Expression - Global Search Between 2 Whole Words

风流意气都作罢 提交于 2020-01-03 02:54:12
问题 I'm attempting to search for content between 2 whole words using a regular expression. For example: all the girls went to the mall in town. In the above string I want to find the content between the word all and to : (?<=all).*?(?=to)/g However, it's finding two matches since the expression is not instructed to search between whole words only: " the girls went " //between all and to " in " //between m(all) and (to)wn I had thought to add spaces in the expression, like this: (?<= all ).*?(?=

R: cbind based on match first few letters or number of a cells

我们两清 提交于 2020-01-02 22:38:40
问题 I have df1 like this: df1 <- data.frame(A=c("x01","x02","y03","z02","x04"), B=c("A01BB01","A02BB02","C02AA05","B04CC10","C01GX02")) A B 1 x01 A01BB01 2 x02 A02BB02 3 y03 C02AA05 4 z02 B04CC10 5 x04 C01GX02 I have df2 like this. X Y 1 a A01BB 2 b A02 3 c C02A 4 d B04 5 e C01GX df2 <- data.frame(X=c("a","b","c","d","e"), Y=c("A01BB","A02","C02A","B04","C01GX")) I want to match the first few letters/ numbers in df1$B with those in df2$Y. And then merge two dataframe based on the best match, as