I have a function that returns the BMI from a given dataframe with columns 'Weight' and 'Height'
Here is the function:
Now, i added new column 'Height In Meters' to the dataframe 'data' with:
What i would like to do next, is to apply the original function on the dataframe 'data',
but instead of using the column 'Height', the calculation would be by using the new column 'Height In Meters'.
the result should be a new column called 'BMI' in the dataframe 'data', that shows for each row the calculation using 'Height In Meters'.
I tried:
But that doesn't seem to work.
Here is the function:
1 2 |
def BMI(data): return data[ 'Weight' ] / (data[ 'Height' ] * * 2 ) |
1 |
data[ 'Height In Meters' ] = data[ 'Height' ] / 100 |
but instead of using the column 'Height', the calculation would be by using the new column 'Height In Meters'.
the result should be a new column called 'BMI' in the dataframe 'data', that shows for each row the calculation using 'Height In Meters'.
I tried:
1 |
data[ 'BMI' ] = data[[ 'Weight' , 'Height In Meters' ]]. apply (BMI,axis = 1 ) |