How to make android prefer mobile data when wifi signal is very weak
From Android 5 onwards, there's a setting in the Developer options called Aggressive WiFi to mobile handover.

Enabling this setting makes your phone switch to mobile connection when the WiFi signal is too weak.

You can also take a look at a tutorial with screenshots.