Built-in health and fitness calculations
What are Expressions?
Expressions are pre-built calculations that you can apply to your data. Additory includes 12 built-in health and fitness expressions that calculate common metrics like BMI, body surface area, and fitness scores.
How to use expressions:
add.expression_name(df) to apply calculationsScenario: You have patient data and want to calculate BMI and body surface area.
import pandas as pd
import additory as add
# Patient data with height and weight
patients = pd.DataFrame({
'patient_id': [1, 2, 3, 4, 5],
'name': ['John Doe', 'Jane Smith', 'Mike Brown', 'Sarah Lee', 'Tom Wilson'],
'height': [175, 162, 180, 168, 172], # cm
'weight': [70, 58, 85, 62, 75], # kg
'age': [35, 28, 42, 31, 38]
})
print("Original patient data:")
print(patients)
# Calculate BMI (Body Mass Index)
result = add.bmi(patients)
print("\nWith BMI calculated:")
print(result)
Original patient data:
patient_id name height weight age
0 1 John Doe 175 70 35
1 2 Jane Smith 162 58 28
2 3 Mike Brown 180 85 42
3 4 Sarah Lee 168 62 31
4 5 Tom Wilson 172 75 38
With BMI calculated:
patient_id name height weight age bmi
0 1 John Doe 175 70 35 22.857143
1 2 Jane Smith 162 58 28 22.095808
2 3 Mike Brown 180 85 42 26.234568
3 4 Sarah Lee 168 62 31 21.967120
4 5 Tom Wilson 172 75 38 25.347394
Scenario: You want to calculate multiple health metrics and fitness scores for a comprehensive health assessment.
import pandas as pd
import additory as add
# Comprehensive health data
health_data = pd.DataFrame({
'patient_id': [1, 2, 3, 4, 5],
'name': ['John Doe', 'Jane Smith', 'Mike Brown', 'Sarah Lee', 'Tom Wilson'],
'height': [175, 162, 180, 168, 172], # cm
'weight': [70, 58, 85, 62, 75], # kg
'age': [35, 28, 42, 31, 38],
'gender': ['Male', 'Female', 'Male', 'Female', 'Male'],
'waist': [85, 68, 95, 72, 88], # cm
'hip': [95, 92, 102, 96, 98], # cm
'systolic_bp': [120, 110, 140, 115, 125], # mmHg
'diastolic_bp': [80, 70, 90, 75, 82], # mmHg
'activity_level': [3, 4, 2, 5, 3] # 1-5 scale
})
print("Comprehensive health data:")
print(health_data)
# Calculate BMI
result = add.bmi(health_data)
# Calculate Body Surface Area
result = add.bsa(result)
# Calculate Waist-Hip Ratio
result = add.waist_hip_ratio(result)
# Calculate Basal Metabolic Rate
result = add.bmr(result)
# Calculate Age Category
result = add.age_category(result)
# Calculate Blood Pressure Category
result = add.blood_pressure_category(result)
# Calculate Fitness Score
result = add.fitness_score(result)
print("\nWith all health metrics calculated:")
print(result[['name', 'bmi', 'bsa', 'waist_hip_ratio', 'bmr', 'age_category', 'blood_pressure_category', 'fitness_score']])
Comprehensive health data:
patient_id name height weight age gender waist hip systolic_bp diastolic_bp activity_level
0 1 John Doe 175 70 35 Male 85 95 120 80 3
1 2 Jane Smith 162 58 28 Female 68 92 110 70 4
2 3 Mike Brown 180 85 42 Male 95 102 140 90 2
3 4 Sarah Lee 168 62 31 Female 72 96 115 75 5
4 5 Tom Wilson 172 75 38 Male 88 98 125 82 3
With all health metrics calculated:
name bmi bsa waist_hip_ratio bmr age_category blood_pressure_category fitness_score
0 John Doe 22.857143 1.834615 0.894737 1679.750000 Adult Normal 6.5
1 Jane Smith 22.095808 1.598847 0.739130 1369.500000 Adult Normal 7.2
2 Mike Brown 26.234568 2.041463 0.931373 1834.250000 Adult Hypertension 4.8
3 Sarah Lee 21.967120 1.693847 0.750000 1423.000000 Adult Normal 8.1
4 Tom Wilson 25.347394 1.871615 0.897959 1754.750000 Adult Normal 6.8
# Single expression
result = add.bmi(df)
# Chain multiple expressions
result = add.bmi(df)
result = add.bsa(result)
result = add.bmr(result)
# Or chain in one line
result = add.fitness_score(add.bmr(add.bsa(add.bmi(df))))
# Check what expressions are available
print(dir(add)) # Shows all available functions and expressions