When I try to make a dataframe
of these two series with differing indices pandas doesn't preserve the order of the columns from the series as shown below.
index = ['one','two','three','four','five','six','seven','eight','nine','ten']
index2 = index[:9] + ['Ha']
a = pd.Series(list(range(10)), index = index)
b = pd.Series(list(range(10)), index = index2)*2
df = pd.DataFrame([a,b], index = ['tens','times2'])
Outputs
Ha eight five four nine one seven six ten three two
But when I make the dataframe
with the series having the same indices the original column order (the order of the list index
) is preserved. Why is this happening?