Displayed DataFrame doesn't Match Code

Course Name: Python For Trading!, Section No: 5, Unit No: 1, Unit type: Video

At 2:35 in the video, I think the DataFrame displayed doesn't match the code used. How come the 'three' column is before the 'two' column? 

Hey Norsay,



When we create a dataframe from a dictionary, the order will not necessarily be the same as specified in the code. So it is possible for 'three' column to appear before 'two' column. 



To preserve the order as it is in the code, you can pass the column variable at the end. So the code will look something like this:

 

df = pd.DataFrame({'one':pd.Series(np.random.randn(3), index=['a,'b','c']),
                   'two':pd.Series(np.random.randn(4), index=['a,'b','c','d']),
                   'three':pd.Series(np.random.randn(3), index=['a,'b','c'])},
                   columns=['one', 'two', 'three'])

Hope this helps!

Thanks,
Rushda