我愿意在python pandas中这样做,但在R中我有以下df:
result<-structure(list(traffic_Count_Street = c("San Angelo", "W Commerce St",
"W Commerce St", "S Gevers St", "Austin Hwy", "W Evergreen St"
), unit_Street = c("San Pedro Ave", "W Commerce", "W Commerce",
"S New Braunfels", "Austin Highway", "W Cypress")), .Names = c("traffic_Count_Street",
"unit_Street"), row.names = c(1L, 17L, 18L, 34L, 260L, 273L), class = "data.frame")
1 San Angelo San Pedro Ave
17 W Commerce St W Commerce
18 W Commerce St W Commerce
34 S Gevers St S New Braunfels
260 Austin Hwy Austin Highway
273 W Evergreen St W Cypress
对于每一行,如果其中一个大于3个字符的单词与另一个匹配,我想部分匹配第1列到第2列。你知道吗
我将删除:
1 San Angelo San Pedro Ave
34 S Gevers St S New Braunfels
273 W Evergreen St W Cypress
并保持:
17 W Commerce St W Commerce
18 W Commerce St W Commerce
260 Austin Hwy Austin Highway
我尝试用以下方式使用stringR
,但没有成功:
result$unit_Street[str_detect(result$traffic_Count_Street, "\\w{3}")]
创建具有阈值调整的距离过滤器。然后你可以调整,直到你得到你想要的结果。在这种情况下,Levenshtein距离为5效果良好:
要了解更多信息,请参见the wiki page和R doc help page
相关问题 更多 >
编程相关推荐