I am coding a Python function that takes an input and displays all the matching values from the dataframe but I don't get any results from an input containing a single quote (apostrophe) '
The dataframe contains values like: Mo'Nique, Thaddeus O'Sullivan, Nancy O'Dell which I can't match by typing the corresponding name.
I have tried to escape the single quote with .replace("'", "\'") but didn't work.
Thanks for your help.
NOTE: I am parsing the values twice. First time I search for a match, if none found, I normalize the value and search again before printing name not found.
import pandas as pd
def get_name():
request_name = input("Type a name: ")
request_name = request_name.lower().title().strip()
search = False
for value in df['NameColumn']:
if request_film in value:
search = True
if not search:
df['NameColumn'] = (
df['NameColumn'].str.normalize('NFKD').str.encode(
'ascii', errors='ignore').str.decode('utf-8'))
for value in df['NameColumn']:
if request_name in value:
search = True
if search:
name_data = df.loc[(df['NameColumn'].str.contains(request_name))]
print(name_data)
else:
print("name not found")
the single quotes in your df are possibly non-ASCII characters. If it's the case then you can use the
Unidecodepackage to convert Unicode characters to their ASCII equivalent. You can try this :Then you get :