I’m trying to use double quotes so that a search term within double quotes instructs the system to treat it as a string literal to enable precise matching of the exact phrase.
Here is my code:
import pandas as pd
excel_file = 'excel.xlsx'
df = pd.read_excel(excel_file)
input_region= input("Type a string:")
Define a search function
def search_string(s, search):
s = "Peninsular “PM419, PM342”" # how to achieve right pattern??
return search in str(s)
Search for the string in all columns
mask = df.apply(lambda x: x.map(lambda s: search_string(s, input_region)))
Filter the DataFrame based on the mask
filtered_df = df.loc[mask.any(axis=1)]
print(filtered_df)