Skip to content
Advertisement

converting percentage values into numbers in python dataframe

I am getting hold of data from google sheet(consisting of 26 columns) into a python dataframe. 4 columns A,B,C,D have data in the form of % values(eg 15.6%) and also contain some rows with N/A values. I am trying to convert these columns into numbers so that I can use them for other calculations, but am having problems doing so. The output for all the rows is 1.0000 using my code, but I want it to be 0.156(from 15.6%) This is the code I am using

JavaScript

I have been trying to find a solution for the past 3 hrs, but nothing seems to work:/ I feel the main problem here could be the presence of N/A values which can’t be transformed using the astype() Sample dataset: enter image description here

Solution: Thanks to @PraysonW.Daniel

JavaScript

Advertisement

Answer

These are the steps I took

JavaScript

First I selected the columns we are interested in, then replace % with “ , force values to numeric and last divided by 100

Data and Results

JavaScript
Advertisement