熊猫排序MultiIndex数据透视表

时间:2016-05-18 20:36:22

标签: sorting python-3.x pandas pivot-table multi-index

给出以下数据透视表:

import UIKit
var wreath = 0
var box = 0




class ViewController: UIViewController {
@IBOutlet weak var YouHaveB: UILabel!
@IBOutlet weak var YouHaveW: UILabel!

@IBAction func Wreaths(sender: AnyObject) {
    wreath += 1
    YouHaveW.text = "You Have \(wreath) Wreaths"

}
@IBAction func Boxes(sender: AnyObject) {
    box += 1
    YouHaveB.text = "You Have \(box) Boxes"
}


override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

我想在2016年前对行(A组和B组)进行排序,使B组在A组之上,同时保留数据透视表的整体布局。

提前致谢!

1 个答案:

答案 0 :(得分:3)

使用sort_values

t.sort_values(('Count', 2016))

元组('Count', 2016)是要排序的列的名称。

看起来像:

       Count               
YYYYMM  2013 2014 2015 2016
Group                      
B          9    8    7    4
A          7    2    6    5