Automatically switching WiFi
As of now, at least on the Nexus 6P which is a Nexus and all of this should apply, the only way I've been able to stop situations like that where my phone is trying to connect to a weak Wi-Fi signal is to go into the Settings, tap on the network, and click "FORGET".

However, as far as current features in Android go, there's no way to prioritize Wi-Fi networks without an app from the Google Play Store.