contains

Column contains column 1

本小妞迷上赌 提交于 2020-01-15 09:13:15
问题 I have a dataframe. I can test whether, (C), on each row, the number in column (B) is in the string column (A). df = pd.DataFrame({'A': ["me 1 23", "me", "123", "me 12", "12 me"], 'B': [123, 123, 123, 12, 12 ]}) df = df.dropna() df['C']=df.A.str.contains(r'\b(?:{})\b'.format('|'.join(df.B.astype(str)))).astype(int) print(df) This gives the correct answer: A B C 0 me 1 23 123 0 1 me 123 0 2 123 123 1 3 me 12 12 1 4 12 me 12 1 But when I change the number (B) on row 1 I get the incorrect answer

What's more efficient in Python: `key not in list` or `not key in list`? [duplicate]

╄→尐↘猪︶ㄣ 提交于 2020-01-13 19:43:57
问题 This question already has answers here : “x not in y” or “not x in y” (6 answers) Closed 2 years ago . Just found out that both syntax ways are valid. Which is more efficient? element not in list Or: not element in list ? 回答1: They behave identically, to the point of producing identical byte code; they're equally efficient. That said, element not in list is usually considered preferred. PEP8 doesn't have a specific recommendation on not ... in vs. ... not in , but it does for not ... is vs. .

Java Crazyness - Contains fails when equals passes

蓝咒 提交于 2020-01-13 11:07:49
问题 This is the most crazy thing I have seen in java (1.6): Set<ActionPlan> actionPlans = assessment.getActionPlans(); //getActionPlans() returns a java.util.HashSet<ActionPlan> ActionPlan actionPlan = actionPlans.iterator().next(); assertTrue(actionPlan1.equals(actionPlan)); assertEquals(actionPlan1.hashCode(), actionPlan.hashCode()); assertTrue(actionPlans.contains(actionPlan1)); The first two asserts pass but the last one fails. I'm not giving you details on the ActionPlan and Assessment

Java Crazyness - Contains fails when equals passes

家住魔仙堡 提交于 2020-01-13 11:06:08
问题 This is the most crazy thing I have seen in java (1.6): Set<ActionPlan> actionPlans = assessment.getActionPlans(); //getActionPlans() returns a java.util.HashSet<ActionPlan> ActionPlan actionPlan = actionPlans.iterator().next(); assertTrue(actionPlan1.equals(actionPlan)); assertEquals(actionPlan1.hashCode(), actionPlan.hashCode()); assertTrue(actionPlans.contains(actionPlan1)); The first two asserts pass but the last one fails. I'm not giving you details on the ActionPlan and Assessment

MySQL Spatial CONTAINS shows wrong result

泪湿孤枕 提交于 2020-01-13 10:24:08
问题 I have a strange behavior of MySQL spatial search. I have created a polygon in a GEOM field (Portugal bounds), then I am trying to find a point inside -- it is found ok. The next try is to find a point that is outside a polygon but the query still returns 1 found row. Please help, what am I doing wrong? Why does it find a point outside a polygon? SQL Code for testing is below: CREATE TABLE IF NOT EXISTS `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `bounds` geometry NOT NULL, PRIMARY KEY (

XPath: using regex in contains function

送分小仙女□ 提交于 2020-01-08 16:03:25
问题 I would like to match the following text sometext12345_text using the below regex. I'm using this in one of my selenium tests. String expr = "//*[contains(@id, 'sometext[0-9]+_text')]"; driver.findElement(By.xpath(expr)); It doesn't seem to work though. Can somebody help? 回答1: XPath 1.0 doesn't handle regex natively, you could try something like //*[starts-with(@id, 'sometext') and ends-with(@id, '_text')] (as pointed out by paul t, //*[boolean(number(substring-before(substring-after(@id,

Get elements containing text from array

て烟熏妆下的殇ゞ 提交于 2020-01-07 04:39:07
问题 I want to search all the elements containing any string in the array. For example I have following list of items <ul> <li>cricket bat</li> <li>tennis ball</li> <li>golf ball</li> <li>hockey stick</li> </ul> and this array var arr = ['bat', 'ball']; It should select all the elements having text bat and ball. How can I achieve this using jquery or javascript. This is what I was trying filter = 'bat ball'; var lis = row('UL li'); var flag = 0; for (var i = 0; i < lis.length; i++) { var name =

Split string by uppercase words/chars and numerics

北城余情 提交于 2020-01-06 08:43:31
问题 I have the string like this - "H2SO4liH2", i need to split this string by uppercase elements and numerics. At the out i need to get array like this "H2", "S", "O4", "Li", "H2" or "H", "2", "S", "O", "4", "Li", "H", "2" 回答1: This uses the pattern provided in toheedNiaz's answer but in a Swift context: let string = "H2SO4LiH2" let pattern = "[A-Z][^A-Z]*" do { let regex = try NSRegularExpression(pattern: pattern) let matches = regex.matches(in: string, range: NSRange(string.startIndex..., in:

check if string contains any of the elements of a stringarray (vb net)

与世无争的帅哥 提交于 2020-01-06 06:14:49
问题 I´ve got a little problem. At the end of a programm it should delete a folder. In ordern to deny deletion of a folder, which directory contains a certain word, I wanted to check if a string (the directory.fullname.tostring) contains any of the elements which are stored in a string array. The string array contains strings stating the exception words. This is how far I got and I know that the solution is the other way round than stated here: If Not stackarray.Contains(dir.FullName.ToString)

searching a keyword in DAX

亡梦爱人 提交于 2020-01-06 05:07:48
问题 I am trying to create a column in power BI that searches for a keyword in a column of a table and returns a category. For example: in table 1 there is a column with feedback and if it contains any keyword in the keyword column of table 2 ( which is updated regularly) a TRUE value is returned. The following code works great if the keyword is the only word in the sentence like "product broke after using it once" returns FALSE if looking for the keyword "broke" and the word "broke" used as the