Remove series of characters in pandas



Somewhat of a beginner in pandas.

I am trying to clean data in a specific column by removing a series of characters.

Currently the data looks like this:

**Column A**

 (F) Red Apples

 (F) Oranges 

 Purple (F)Grapes

 (F) Fried Apples

I need to remove the (F)

I used … df[‘Column A’]=df[‘Column A’].str.replace(‘[(F)]’,’ ‘)

This successfully removed the (F) but it also removed the other F letters (for example Fried Apples = ied Apples) How can I only remove the “series” of characters.

Answer

Try this –

df['Column A'].str.replace('(F)','')
0       Red Apples
1          Oranges
2    Purple Grapes
3     Fried Apples
Name: Column A, dtype: object

OR

df['Column A'].str.replace('(F)','', regex=False)


Source: stackoverflow