I am trying to create a heat map but the plot just returns an empty 2D object with no plot. I suspect its because my values are in percentages. is there a function for me to convert all the values to floats? Thank you.
            Asked
            
        
        
            Active
            
        
            Viewed 734 times
        
    1
            
            
        - 
                    3Does this answer your question? [Convert percent string to float in pandas read\_csv](https://stackoverflow.com/questions/25669588/convert-percent-string-to-float-in-pandas-read-csv) – Mohammad Aug 03 '21 at 15:46
- 
                    1yeah it does, thank you – mlboy Aug 03 '21 at 19:19
1 Answers
1
            
            
        Supposing the pd.DataFrame was already created, one approach is to use pandas replace. Say I have the following DataFrame:
df = pd.DataFrame([['10.1%','20.25%'],['40.45%', '50.52%'], ['30.3%', '60.7%']], columns=['foo', 'bar'])
You can use replace to get rid of the % sign:
df = df.replace('%','', regex=True)
Finally, you could cast all columns to np.float64 as needed:
df.astype(np.float64)
 
    
    
        luizbarcelos
        
- 686
- 5
- 17

 
     
    
