How To Select Rows Which One Of Its Columns Values Contains Specific String In Python?
how to select rows which one of its columns values contains specific string in python? I have used the one mentioned here and got errors while I used sample data frame and it looks
Solution 1:
+
is special regex char (match one or more repetitions), so need escape it:
df = pd.DataFrame({'DESCRIPTION': ['aa+','a','+']})
df = df[df['DESCRIPTION'].str.contains('\+')]
print(df)
DESCRIPTION
0 aa+
2 +
Or add parameter regex=False
:
df[df['DESCRIPTION'].str.contains('+', regex=False)]
Post a Comment for "How To Select Rows Which One Of Its Columns Values Contains Specific String In Python?"