0

I'm trying to apply a filter to a dataframe based on whether a certain string is a substring of the values in a column.

For example: Let's call the substring 'X' and I want to retrieve all rows where 'X' is a substring of the value in a column called 'A'.

It feels like the code should look something like this:

df["X" in df.A]

or this:

df.loc("X" in df.A) 

or something along those lines. Does anyone have an idea on how I can achieve this?

tawab_shakeel
  • 3,345
  • 5
  • 23

1 Answers1

3

try this

res = df[df['A'].str.contains("X")]
tawab_shakeel
  • 3,345
  • 5
  • 23