I'll use CO2 as an example.
So the energy-level diagram for the carbon has: one 1s orbital, two 2sp orbitals and two 2p orbitals, listed from lowest to highest energy.
Ignoring the 1s, there are 4 valence electrons. In my way of thinking, the lowest energy shells should be filled first, so we would have
in the sp hybridised orbitals, and 'empty' 2p orbitals.
But clearly, there's a pi bond, so in reality we have
in the 2sp orbitals and
in the 2p orbitals.
Where is my thinking going wrong? Thanks!