1

I carefully read the post Select by partial string from a pandas DataFrame but I think it doesn't address my problem. I need to filter rows of a dataframe if a row value can be found within the string.

Example, my table is:

Part_Number
A1127
A1347

I want to filter records if column value is within the string ZA1127B.48. The filtered dataframe should contain row 1. (All the posts show how to check if row value contains a string.)

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
Artup
  • 49
  • 4

2 Answers2

0

You can use .apply + in operator:

s = "ZA1127B.48"

print(df[df.apply(lambda x: x.Part_Number in s, axis=1)])

Prints:

  Part_Number
0       A1127
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
0

I think using the apply function will help you to do what you want.

Try this line:

df[df["Part_Number"].apply(lambda x: x in "ZA1127B.48")]