Consider the (long) code snippet here. Unless you remove ccode from the df beforehand, you end up with all object dtype for df after unstack. http://www.pastie.org/2904328