I have a very large dataframe, part of which looks like this:
| col1 | col2 |
|---|---|
| A | 3 |
| A | 4 |
| B | 5 |
| B | 7 |
I know all rows with the same value in col1 should have the same value in col2, and any deviation is due to measuring uncertainty. I want to assign the cells in col2 the average value for all col2 cells in rows with the same col1 value, resulting in something like this:
| col1 | col2 |
|---|---|
| A | 3.5 |
| A | 3.5 |
| B | 6 |
| B | 6 |
The real dataset is too large to do this manually for each individual unique col1 value. Does anyone have any idea on how to automate this? Thanks in advance.