Spaces:
Sleeping
Sleeping
Download api/feature_engineering.py from radwaamr1/desertification-api: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/radwaamr1/desertification-api/resolve/main/api/feature_engineering.py
- Command line
-
hf download hf://spaces/radwaamr1/desertification-api/api/feature_engineering.py
-
curl -L -o feature_engineering.py https://huggingface.co/spaces/radwaamr1/desertification-api/resolve/main/api/feature_engineering.py
1.01 kB
| import pandas as pd | |
| import numpy as np | |
| def feature_engineering(input_df: pd.DataFrame) -> pd.DataFrame: | |
| # Get season | |
| def get_season(month): | |
| if month in [12, 1, 2]: | |
| return 'Winter' | |
| elif month in [3, 4, 5]: | |
| return 'Spring' | |
| elif month in [6, 7, 8]: | |
| return 'Summer' | |
| else: | |
| return 'Autumn' | |
| input_df['season'] = input_df['month'].apply(get_season) | |
| # Soil ratios | |
| input_df['soil_total'] = input_df['sand'] + input_df['silt'] + input_df['clay'] | |
| input_df['soil_total'] = input_df['soil_total'].replace(0, np.nan) | |
| input_df['sand_ratio'] = input_df['sand'] / input_df['soil_total'] | |
| input_df['silt_ratio'] = input_df['silt'] / input_df['soil_total'] | |
| input_df['clay_ratio'] = input_df['clay'] / input_df['soil_total'] | |
| input_df = input_df.drop(columns=['soil_total']) | |
| # Combined feature | |
| input_df['soc_cec'] = input_df['soc'] * input_df['cec'] | |
| return input_df | |