On the parity of ranks of Selmer groups IV. With an appendix by Jean-Pierre Wintenberger