I have a dataframe and I try to get string, where on of column contain some string Df looks like
member_id,event_path,event_time,event_duration
30595,\"2016-
You can use str.match instead. In your code:
res = df[df['event_time'].str.match('|'.join(substr), regex=True)]
The warning is triggered by str.contains
when the regular expression includes groups, e.g. in the regex r'foo(bar)'
, the (bar)
part is considered a group because it is in parenthesis. Therefore you could theoretically extract that from a regex.
However, the warning doesn't make sense in the first place, contains
is supposed to only "test if pattern or regex is contained within a string of a Series or Index" (pandas documentation). There is nothing about extracting groups.
In any case, str.match
does not throw the warning, and currently does almost the same as str.contains
except that (1) the string must exactly match and (2) one cannot deactivate regex from str.match
(str.contains
has a regex
parameter to deactivate them)