Expressions

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:

📋 Available Expressions

🚀 Basic Usage Example

Scenario: You have patient data and want to calculate BMI and body surface area.

Setup: Create sample patient data
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 using expression
# Calculate BMI (Body Mass Index)
result = add.bmi(patients)

print("\nWith BMI calculated:")
print(result)
Output
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

🎯 Advanced Usage Example

Scenario: You want to calculate multiple health metrics and fitness scores for a comprehensive health assessment.

Setup: Comprehensive health data
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 multiple health metrics
# 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']])
Output
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

📚 Complete Expressions List

add.bmi(df)
Body Mass Index - measures body fat based on height and weight
Requires: height, weight
add.bmi2(df)
Alternative BMI calculation with different precision
Requires: height, weight
add.bmi3(df)
Third BMI variant with enhanced calculation
Requires: height, weight
add.bsa(df)
Body Surface Area - used in medical dosage calculations
Requires: height, weight
add.waist_hip_ratio(df)
Waist-to-Hip Ratio - indicator of health risk
Requires: waist, hip
add.body_fat_percentage(df)
Estimated body fat percentage
Requires: height, weight, age, gender
add.bmr(df)
Basal Metabolic Rate - calories burned at rest
Requires: height, weight, age, gender
add.ideal_body_weight(df)
Ideal body weight based on height and gender
Requires: height, gender
add.blood_pressure_category(df)
Blood pressure category (Normal, High, etc.)
Requires: systolic_bp, diastolic_bp
add.cholesterol_ratio(df)
Total cholesterol to HDL ratio
Requires: total_cholesterol, hdl_cholesterol
add.age_category(df)
Age category (Child, Adult, Senior, etc.)
Requires: age
add.fitness_score(df)
Overall fitness score based on multiple factors
Requires: age, bmi, activity_level

⚠️ Important Notes

Column Detection: Expressions automatically detect required columns by name.
Missing Columns: If required columns are missing, expressions will show helpful error messages.
Units: Expressions expect standard units (cm for height, kg for weight, etc.).
Medical Disclaimer: These calculations are for informational purposes only and should not replace professional medical advice.

🎯 Quick Reference

Basic expression usage patterns
# 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