Most of the statements in the if/else are common and can be moved out if you do this in else  
```
column = groupby + '.' + column
```