我有一个通过groupby操作创建的多索引DataFrame.我正在尝试使用索引的几个级别进行复合排序,但我似乎找不到能够满足我需要的排序函数.
初始数据集看起来像这样(各种产品的每日销售额):
Date Manufacturer Product Name Product Launch Date Sales
0 2013-01-01 Apple iPod 2001-10-23 12
1 2013-01-01 Apple iPad 2010-04-03 13
2 2013-01-01 Samsung Galaxy 2009-04-27 14
3 2013-01-01 Samsung Galaxy Tab 2010-09-02 15
4 2013-01-02 Apple iPod 2001-10-23 22
5 2013-01-02 Apple iPad 2010-04-03 17
6 2013-01-02 Samsung Galaxy 2009-04-27 10
7 2013-01-02 Samsung Galaxy Tab 2010-09-02 7
Run Code Online (Sandbox Code Playgroud)
我使用groupby来获取日期范围的总和:
> grouped = df.groupby(['Manufacturer', 'Product Name', 'Product Launch Date']).sum()
Sales
Manufacturer Product Name Product Launch Date
Apple iPad 2010-04-03 …Run Code Online (Sandbox Code Playgroud)