Questions tagged [pivot-table]

A "pivot table" is a method of summarizing data in tabular form. Typically, these have a category column in the left hand side, and multiple summary columns to the right. Each different category will have its own row. Be sure to include the relevant language tag (python, excel, R, postgreSQL etc.) on your question.

A "pivot table" is a method of summarizing data in tabular form. Typically, these have a category column in the left hand side, and multiple summary columns to the right. Each different category will have its own row.

Pivot tables are typically found in data visualization programs, including spreadsheets and business intelligence. Note that a "pivot table" is also known as a "cross tab" or "cross tabulation".

Resources:

8105 questions
7
votes
1 answer

How to pivot a table with d3.js?

Consider the following tabular data (just an…
kjo
  • 33,683
  • 52
  • 148
  • 265
7
votes
2 answers

Dynamic pivot null to 0

I've got a stored procedure that is taking data from one table, running through my dynamic pivot stored procedure, and outputting into the page. The problem is, there is a substantial number of null entries. When I process this data on the page, I'm…
ProjectUI
  • 75
  • 1
  • 2
  • 7
7
votes
3 answers

Reordering columns/rows of a pivot_table?

pandas's pivot_table seems to return columns only in alphabetical order, such that pivot_table(tips, 'tip_pct', rows=['sex', 'day'], cols='smoker', aggfunc=len) gives: smoker No Yes sex day Female Fri 2 7 Sat 13 …
Jonathan Harford
  • 361
  • 1
  • 3
  • 9
7
votes
2 answers

Calculating Percent of Total in Power Pivot Model

I have created a power pivot table as shown in the picture. I want to calculate quarter over quarter sales change. For which I have to divide for example corporate family "Acer" 's sales in 2012Q4 by sum of all the corporate family. I am using…
SAM244776
  • 1,375
  • 6
  • 18
  • 26
7
votes
2 answers

How to get min value in a group?

Example: ID Value MAX Group1 2 6 Group1 4 6 Group1 6 6 Group2 1 3 Group2 3 3 Group3 7 8 Group3 4 8 Group3 2 8 Group3 8 8 Group4 1 3 Group4 2 3 Group4 3 3 Group5 7 7 The column 'MAX' has the results I…
Raymond
  • 3,382
  • 5
  • 43
  • 67
7
votes
1 answer

Excel pivot-tables subtotals

I am trying to build a pivot table in Excel to summarize some data, like I want columns A and B to be in compact form and column C to be outlined; also I need subtotals for the B column. Letting subtotals appear on the last row, everything works…
caseroR
  • 71
  • 1
  • 4
7
votes
1 answer

Using an OR condition to filter an Excel Pivot Table

I'm an Excel amateur and I'm just starting to learn to use Pivot Tables. The issue is, I need the pivot table filtered results to be inclusive. So, I have a table with some data rows and 3 Columns A, B, C with possible values X, Y, Z... I specify a…
cesil99
  • 103
  • 1
  • 1
  • 6
6
votes
3 answers

c++ pivot table implementation

Similar to this question Pivot Table in c#, I'm looking to find an implementation of a pivot table in c++. Due to the project requirements speed is fairly critical and the rest of the performance critical part project is written in c++ so an…
shuttle87
  • 15,466
  • 11
  • 77
  • 106
6
votes
6 answers

Pivot dataframe to keep column headings and sub-headings in R

I am trying to pivot a table that has headings and sub-headings, so that the headings go into a column "date", and the subheadings are two columns instead of repeating. Here is an example of my data. This was produced using dput(), so while in the…
cgxytf
  • 421
  • 4
  • 11
6
votes
1 answer

Pandas pivot_table fails with columns and margin

I'm getting a KeyError: "... not in index" while using pivot_table of pandas. Here is sample code: arrays = [['bar', 'bar', 'foo', 'foo'], ['one', 'two', 'one', 'two'], ['A','A','B','B']] tuples = list(zip(*arrays)) index =…
David Makovoz
  • 1,766
  • 2
  • 16
  • 27
6
votes
1 answer

Why doesn't `pivot_wider` work on a `data.table`

A simple example of long to wide pivot: library(tidyverse) library(data.table) df <- data.frame(names=letters[1:3],values=1:3) df %>% pivot_wider(names_from=names,values_from=values) #works dt <- data.table(names=letters[1:3],values=1:3) dt %>%…
LucasMation
  • 2,408
  • 2
  • 22
  • 45
6
votes
3 answers

"Pivot" a Pandas DataFrame into a 3D numpy array

Given a DataFrame with the following structure: Date | Site | Measurement Type | Value ----------------------------------------------- 1/1/2020 | A | Temperature | 32.3 1/2/2020 | B | Humidity | 70% I would like to create…
LoLa
  • 1,260
  • 3
  • 12
  • 17
6
votes
1 answer

Can I use CSV file as Excel pivot data source?

I have some external csv/txt files and I'd like to use them for a pivot table. However, after I selected my csv file as the external data source, at the end of the guided procedure (header, seperators, etc.) Excel throws an error saying something…
ThinkTank
  • 194
  • 1
  • 7
6
votes
2 answers

Joining Multiple Dynamic Pivot Tables

I haven't seen a question like this, but if there is one out there that has been answered, please let me know. I have to create an export, using a stored procedure. Unfortunately, at this time, creating this report in SSRS is not possible. What I…
DataGirl
  • 429
  • 9
  • 21
6
votes
1 answer

pandas pivot_table aggfunc/values parameters behaving oddly

I have this data set: np.random.seed(0) test = pd.DataFrame({ 'a' : np.random.randint(0, 10, size=(10,)), 'b' : np.random.randint(0, 10, size=(10,)), 'c' : np.random.randint(0, 10, size=(10,)), 'd' : np.random.randint(0, 10,…
Ian Thompson
  • 2,914
  • 2
  • 18
  • 31