I think a good way to understand what is going on is to try with the order of the state flipped:
pop = {'Ohio': {2000: 1.5, 2001: 1.7,2002: 3.6}, 'Nevada': {2001: 2.4, 2002: 2.9}}
Now you get:
Ohio Nevada
2000 1.5 NaN
2001 1.7 2.4
2002 3.6 2.9
So what happened in the original? It goes through Nevada first which just has index of 2001 and 2002. THEN it goes through Ohio which has a new index (2000) which is added to the bottom, and two old indexes (2001 and 2002) which already exist and so the values are added in the appropriate spots.
As why it shows up in the book sorted, it is probably a Pandas version difference. Modern Pandas (post v0.25. See Docs) maintains the key order as specified. The book was probably written for an older version of pandas which happened to (randomly) use Ohio first.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…