Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas replace % with calculated

def FormatPerc(x): # Create the function to be applied
    perc = 0
    x = str(x)
    
    if '%' in x:
        x = x.replace("%","")
        perc = float(x)*0.001
    else:
        x = x.replace("%","")
        perc = float(x)   
    
    return perc
  
# in your pandas script:
investments['WithdrawPercentage'] = investments['WithdrawPercentage'].apply(FormatPerc)
# any values like "xx.x%" will now be formatted as 0.xxx
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #replace #calculated
ADD COMMENT
Topic
Name
1+3 =