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:
JavaScript
x
10
10
1
**Column A**
2
3
(F) Red Apples
4
5
(F) Oranges
6
7
Purple (F)Grapes
8
9
(F) Fried Apples
10
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.
Advertisement
Answer
Try this –
JavaScript
1
2
1
df['Column A'].str.replace('(F)','')
2
JavaScript
1
6
1
0 Red Apples
2
1 Oranges
3
2 Purple Grapes
4
3 Fried Apples
5
Name: Column A, dtype: object
6
OR
JavaScript
1
2
1
df['Column A'].str.replace('(F)','', regex=False)
2