We use inelastic neutron scattering to study spin excitation anisotropy in mechanically detwinned Ba(Fe1-xCox)2As2 with x = 0.048 and 0.054. Both samples exhibit a tetragonal-to-orthorhombic structural transition at Ts, a collinear static antiferromagnetic (AF) order at wave vector Q1 = QAF = (1, 0) below the Neel temperature TN, and superconductivity below Tc (Ts > TN > Tc). In the high temperature paramagnetic tetragonal phase (T > Ts), spin excitations centered at Q1 and Q2 = (0, 1) are gapless and have four-fold (C4) rotational symmetry. On cooling to below TN but above Tc, spin excitations become highly anisotropic, developing a gap at Q2 but still are gapless at Q1. Upon entering into the superconducting state, a neutron spin resonance appears at Q1 with no magnetic scattering at Q2. By comparing these results with those from angle resolved photoemission spectroscopy experiments, we conclude that the anisotropic shift of the dyz and dxz bands in detwinned Ba(Fe1-xCox)2As2 below Ts is associated with the spin excitation anisotropy, and the superconductivity-induced resonance arises from the electron-hole Fermi surface nesting of quasiparticles with the dyz orbital characters.