regex - python pandas.Series.str.contains words with space -
i'm trying find strings contain either " internet ", " program ", " socket programming " in pandas dataframe.
df.col_name.str.contains(" internet | program | socket programming ", case=false)
is right way so? or need escape space using \ , raw string?
here small demo:
in [250]: df out[250]: txt 0 internet 1 there no internet in apartment 2 program2 3 learning socket programming in [251]: df.txt.str.contains(" internet | program | socket programming ", case=false) out[251]: 0 false 1 true 2 false 3 true name: txt, dtype: bool
if want "match" first row: internet
:
in [252]: df.txt.str.contains(r"\b(?:internet|program|socket\s+programming)\b", case=false) out[252]: 0 true 1 true 2 false 3 true name: txt, dtype: bool
Comments
Post a Comment