I have a pandas dataframe which has the following layout:
| Column | data type |
|---|---|
| 'Water-Binder' | float |
| 'Fly Ash' | float |
| 'Age' | int |
| 'Strength %' | float |
The age column is qualitative, features records at 1, 3, 7, 14, and 28 days. I want to group the rows by water-binder and fly ash, calculate the mean Strength % for the groups at each age, resulting in a table looking something like this:
| Column | data type |
|---|---|
| 'Water-Binder' | float |
| 'Fly Ash' | float |
| 'Mean Strength % 1 day' | float |
| 'Mean Strength % 3 days' | float |
| 'Mean Strength % 7 days' | float |
| 'Mean Strength % 14 days' | float |
| 'Mean Strength % 28 days' | float |
I've been trying to figure out how this could be done. This is the closest thing to something that works that I've managed to achieve:
age_strength_model = data[['Water-Binder', 'Fly Ash', 'Age', 'Strength %']].copy()
ages = np.unique(age_strength_model['Age'].values)
# create table investigating the relationship between fly ash, age, and compressive strength
for a in ages:
age_strength_model.query(f'`Fly Ash` == 0 & Age == {a}').groupby(['Water-Binder'])['Strength %'].transform(lambda x: x.mean())
However, that just shows me the values rather than organising them into a dataset and doesn't accommodate for grouping water-binder and fly ash together. How would I achieve the desired end result here?
