match

How to test if a string contains one of the substrings in a list, in pandas?

How to test if a string contains one of the substrings in a list, in pandas? Question: Is there any function that would be the equivalent of a combination of df.isin() and df[col].str.contains()? For example, say I have the series s = pd.Series([‘cat’,’hat’,’dog’,’fog’,’pet’]), and I want to find all places where s contains any of …

Total answers: 4

checking if year is in the string (4 consecutive digits)

checking if year is in the string (4 consecutive digits) Question: How can I find if a strings in a list contains a year (ex. 1999). I guess I would check for four consecutive digits such as: [1-2][0-9][0-9][0-9] How to check that against a list piece? Here is what I’ve tried already for piece in …

Total answers: 3

Python- how do I use re to match a whole string

Python- how do I use re to match a whole string Question: I am validating the text input by a user so that it will only accept letters but not numbers. so far my code works fine when I type in a number (e.g. 56), it warns me that I should only type letters and …

Total answers: 4

How to test multiple variables for equality against a single value?

How to test multiple variables for equality against a single value? Question: I’m trying to make a function that will compare multiple variables to an integer and output a string of three letters. I was wondering if there was a way to translate this into Python. So say: x = 0 y = 1 z …

Total answers: 31

compare two lists in python and return indices of matched values

compare two lists in python and return indices of matched values Question: For two lists a and b, how can I get the indices of values that appear in both? For example, a = [1, 2, 3, 4, 5] b = [9, 7, 6, 5, 1, 0] return_indices_of_a(a, b) would return [0,4], with (a[0],a[4]) = …

Total answers: 4

Why won't re.groups() give me anything for my one correctly-matched group?

Why won't re.groups() give me anything for my one correctly-matched group? Question: When I run this code: print re.search(r’1′, ‘1’).groups() I get a result of (). However, .group(0) gives me the match. Shouldn’t groups() give me something containing the match? Asked By: dtc || Source Answers: groups is empty since you do not have any …

Total answers: 4

What is the difference between re.search and re.match?

What is the difference between re.search and re.match? Question: What is the difference between the search() and match() functions in the Python re module? I’ve read the Python 2 documentation (Python 3 documentation), but I never seem to remember it. I keep having to look it up and re-learn it. I’m hoping that someone will …

Total answers: 9