Converted a column of a Pandas dataframe to list. Then lowercased all the elements in the list. Now want to keep only alphabets in the elements of the list. I wrote a regular expression for that. The regex is not working.
df_smer_orig = pd.read_csv('sample.csv', engine='python')
df_smer = df_smer_orig['Item'].tolist()
df_smer = [x.lower() for x in df_smer]
for x in df_smer:
print(x)
regex = re.compile('[^a-zA-Z]')
regex.sub('', x)
print(x)
print(df_smer)
Partial output of the code which shows the regex did not work:
agarbathi / incense sticks
agarbathi / incense sticks
worcestershire sauce- 295ml
worcestershire sauce- 295ml