I have a multi-index dataframe that is created through a group-operation. I'm trying to sort a composite using several levels of the index, but I think what I want is that one can get the function in a way.
The initial dataset looks like this (daily sales count of different products): I use the amount over the date range I The group said: So far so good! The last thing I want to do now is , It's like every manufacturer after launching the products, but grouping them under the manufacturer in order - here I am Trying to: When I try SLEVEL () I had previously lost good per-company hierarchy: sort () and sort_index () just failed: I am not obliged to use a multi index for this, but since then the returns are returned by the group (), so I am working with it. The code for the production of initial dataframe is BTD: will be a hack to change the order of the sequence: Sorleval, which (as you have found) Sorts level: and swap back: < In [14]: g.index = g.index.swaplevel (1, 2): [15]: Out [15]: Sales Manufacturer Product Name Product Launch Date Apple iPod 2001-10-23 34 IPad 2010-04-03 30 Samsung Galaxy 2009-04-27 24 Galaxy Tab 2010-09-02 22 I am of the opinion that Sortelval is sorted in the remaining label order Should not, therefore a gythenbo problem will arise. :) Although it is important to mention the document about it. Note: You can first escape from the code> Swapelvel by reordering the order of the initial group:
& gt; Grouped = df.groupby (('Productive', 'Product Name', 'Date of Product Launch']). Zodiac () Sales Manufacturer Product Name Product Launch Date Apple iPad 2010-04-03 30 iPod 2001-10- 23 34 Samsung Galaxy 2009-04-27 24 Galaxy Tab 2010-09-02 22
Sales Producer Product Name Product Launch Date Apple iPod 2001-10-23 34 iPad 2010-04 -03 30 Samsung Galaxy 2009-04-27 24 Galaxy Tab: 2010-09-02 22
& gt; Group Headlawl ('Product Launch Date') Sales Manufacturer Product Name Product Launch Date Apple iPod 2001-10-23 34 Sam Galaxy 2012-04-27 24 Apple iPad 2010-04-03 30 Samsung Galaxy Tab 2010-09-02 22
grouped.sort (['Manufacturer', 'Product Launch Date']) KeyError: There is no item named 'Manufacturer' Productive Group. KeyIare: Manufacturer's name 'item' looks like a simple operation, but I can not understand it. Source = Index (By = [['Manufacturer', 'Date of Product Launch]] Keyyer:
data = {'date': ['2013-01-01', '2013-01-01' , '2013 -01-01', '2013-01-01', '2013-01-02', '2013-01-02', '2013-01-02', '2013-01-02'], 'Manufacturer': ['' App '', '' '' 'Galaxy Tab' '', '' '' '', '' '', '', 'Samsung', 'Samsung', 'Apple', 'Apple', 'Samsung', 'Samsung',], 'Product Name' , 'IPad', 'iPad', 'Galaxy', 'Galaxy Tab'], 'Product Launch Date': ['2001-10-23', 'PD', 'iPad', 'Galaxy', 'Galaxy Tab' 2010-04-03 ',' 2009-04-27 ',' 2010-09-02 ',' 2001-10-23 ',' 2010-04-03 ',' 2009-04-27 ',' 2010- 09-02 '],' Sales': [12, 13, 14, 15, 22, 17 , 10, 7]} df = DataFrame (data, column = ['date', 'creator', 'product name' 'product launch date', 'cells'])
in [11]: g out [ 11]: Sales Manufacturer Product Name Product Launch Date Apple iPad 2010-04-03 30 iPod 2001-10-23 34 Samsung Galaxy 2009-04-27 24 in Galaxy Tab 2010-09-02 22 at [12]: g. Index = g.index.swaplevel (1, 2)
in
[13]: g = g.sortlevel ()
g = df.groupby ( ['Manufacturer', 'Product Launch Date', 'Product Name']). ()
No comments:
Post a Comment