How do you create a “reverse pivot” in Google Sheets?

I wrote a simple general custom function, which is 100% reusable you can unpivot / reverse pivot a table of any size. In your case you could use it like this: =unpivot(A1:D4,1,1,”customer”,”sales”) So you can use it just like any built-in array function in spreadsheet. Please see here 2 examples: https://docs.google.com/spreadsheets/d/12TBoX2UI_Yu2MA2ZN3p9f-cZsySE4et1slwpgjZbSzw/edit#gid=422214765 The following is the … Read more

Convert matrix to 3-column table (‘reverse pivot’, ‘unpivot’, ‘flatten’, ‘normalize’)

To “reverse pivot”, “unpivot” or “flatten”: For Excel 2003: Activate any cell in your summary table and choose Data – PivotTable and PivotChart Report: For later versions access the Wizard with Alt+D, P. For Excel for Mac 2011, it’s ⌘+Alt+P (See here). Select Multiple consolidation ranges and click Next. In “Step 2a of 3”, choose … Read more

Laravel attach pivot to table with multiple values

You can. From this example in Docs (4.2, 5.0): $user->roles()->sync(array(1 => array(‘expires’ => true))); Hardcoded version for the first two rows: $food = Food::find(1); $food->allergies()->sync([1 => [‘severity’ => 3], 4 => [‘severity’ => 1]]); Dynamically, with your arrays $allergy_ids and $severities in a compatible state (size and sort), you shall prepare your sync data before. … Read more

How to get rid of multilevel index after using pivot table pandas?

You need remove only index name, use rename_axis (new in pandas 0.18.0): print (reshaped_df) sale_product_id 1 8 52 312 315 sale_user_id 1 1 1 1 5 1 print (reshaped_df.index.name) sale_user_id print (reshaped_df.rename_axis(None)) sale_product_id 1 8 52 312 315 1 1 1 1 5 1 Another solution working in pandas below 0.18.0: reshaped_df.index.name = None print … Read more

Pandas Pivot tables row subtotals

If you put State and City not both in the rows, you’ll get separate margins. Reshape and you get the table you’re after: In [10]: table = pivot_table(df, values=[‘SalesToday’, ‘SalesMTD’,’SalesYTD’],\ rows=[‘State’], cols=[‘City’], aggfunc=np.sum, margins=True) In [11]: table.stack(‘City’) Out[11]: SalesMTD SalesToday SalesYTD State City stA All 900 50 2100 ctA 400 20 1000 ctB 500 30 … Read more