I have a data frame that looks like this:
| time_stamp | sensor_index | humidity | temperature | pm2.5_a | pm2.5_b |
|---|---|---|---|---|---|
| 2022-07-15 15:00:00 | 51377 | 37.434 | 102.834 | 18.209 | 17.264 |
| 2022-07-11 22:00:00 | 51377 | 31.267 | 102.367 | 7.982 | 8.971 |
| 2022-07-11 00:00:00 | 51377 | 43.533 | 91.5 | 10.518 | 12.260 |
| 2022-07-11 14:00:00 | 51377 | 51.433 | 95.7 | 14.168 | 20.168 |
I'm trying to apply a correction factor that averages pm2.5_a and pm2.5_b if there difference is less than ±5.
The formula is if(pm2.5_a-pm2.5_b is <±5 then 0.52*(average of pm2.5_a & pm2.5_b) - 0.085*humidity + 5.71, else nothing)
My desired output would look like this:
| time_stamp | sensor_index | humidity | temperature | pm2.5_a | pm2.5_b | pm_cor |
|---|---|---|---|---|---|---|
| 2022-07-15 15:00:00 | 51377 | 37.434 | 102.834 | 18.209 | 17.264 | 11.75 |
| 2022-07-11 22:00:00 | 51377 | 31.267 | 102.367 | 7.982 | 8.971 | 7.46 |
| 2022-07-11 00:00:00 | 51377 | 43.533 | 91.5 | 10.518 | 12.260 | 7.93 |
| 2022-07-11 14:00:00 | 51377 | 51.433 | 95.7 | 14.168 | 20.168 |