Remove certain string from entire column in pandas dataframe

user3848207 picture user3848207 · Aug 10, 2018 · Viewed 17.8k times · Source

I have a pandas dataframe df with the contents below:

  Date          Factor       Expiry         Grade  
0 12/31/1991    2.138766     3/30/1992      -3.33% 
1 10/29/1992    2.031381     2/8/1993       -1.06% 
2 5/20/1993     2.075670     6/4/1993       -6.38% 

I would like the remove the % character from all the rows in the Grade column. The result should look like this:

  Date          Factor     Expiry        Grade  
0 12/31/1991    2.138766   3/30/1992     -3.33 
1 10/29/1992    2.031381   2/8/1993      -1.06 
2 5/20/1993     2.075670   6/4/1993      -6.38 

I am using Python v3.6.

Answer

Shaido picture Shaido · Aug 10, 2018

Using str.replace would work:

df['Grade'] = df['Grade'].str.replace('%', '')