code with df for all conditions and final results

There must be a better way to implement this part. For example for reusability. I will try and show you tomorrow.