0

I am trying to createa multilevel index in pandas but when I do a print of hte dataframe, I see something like this.

                                           ask   bid
time                type mat        strk            
2014-03-31 13:30:00 C    2014-04-19 1850  32.0  30.6
2014-03-31 13:35:00 C    2014-04-19 1850  32.8  31.2
2014-03-31 13:40:00 C    2014-04-19 1850  31.9  29.9
2014-03-31 13:45:00 C    2014-04-19 1850  31.6  30.1
2014-03-31 13:50:00 C    2014-04-19 1850  32.6  31.2
2014-03-31 13:55:00 C    2014-04-19 1850  33.6  32.1
2014-03-31 14:00:00 C    2014-04-19 1850  34.4  33.0
2014-03-31 14:05:00 C    2014-04-19 1850  33.5  31.9
2014-03-31 14:10:00 C    2014-04-19 1850  34.0  32.2
.....

The above is a result of

df.set_index(['time', 'type', 'mat', 'strk'], inplace=True)

Now I would have expected to see something more hierarchial like this

                                           ask   bid
time                type mat        strk            
2014-03-31 13:30:00 C    2014-04-19 1850  32.0  30.6
                                    1860  aaaa  bbbb
                         2014-05-17 1850  xxxx  yyyy
                                    1860  xxxx  yyyy
                    P    2014-04-19 1850  mmmm  nnnn
                                    1860  aaaa  bbbb
                         2014-05-17 1850  xxxx  yyyy
                                    1860  xxxx  yyyy 
2014-03-31 13:35:00 C    2014-04-19 1850  32.8  31.2
2014-03-31 13:40:00 C    2014-04-19 1850  31.9  29.9
2014-03-31 13:45:00 C    2014-04-19 1850  31.6  30.1
2014-03-31 13:50:00 C    2014-04-19 1850  32.6  31.2
2014-03-31 13:55:00 C    2014-04-19 1850  33.6  32.1
2014-03-31 14:00:00 C    2014-04-19 1850  34.4  33.0
2014-03-31 14:05:00 C    2014-04-19 1850  33.5  31.9
2014-03-31 14:10:00 C    2014-04-19 1850  34.0  32.2

I have a few rows below for the same time - 2014-03-31 13:30:00 But not sure why I dont see this happeniing. Tried without that 'inplace' options. Still i see the same issue. But in a different place, I do see this hierarchial when i do set_index on a different dataframe. Not sure what I am missing here.

1 Answer 1

1

Sort the dataframe should help

df.sort()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.