What are levels in a pandas DataFrame?

前端 未结 2 1221
天命终不由人
天命终不由人 2020-12-14 02:45

I\'ve been reading through the documentation and many explanations and examples use levels as something taken for granted. Imho the docs lack a bit on a fundame

2条回答
  •  不知归路
    2020-12-14 03:23

    Usually a DataFrame has a 1D index and columns:

        x y
    0   4 1
    1   3 9
    

    Here the index is [0, 1] and the columns are ['x', 'y']. But you can have multiple levels in either the index or the columns:

        x y
        a b c
    0 7 4 1 3
      8 3 9 5
    

    Here the columns' first level is ['x', 'y', 'y'] and the second level is ['a', 'b', 'c']. The index's first level is [0, 0] and the second level is [7, 8].

提交回复
热议问题