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
1
vote
2 answers

How to merge pivot tables in Pandas without duplicates in columns

I have a DataFrame imported from a csv file called test_data that's structured like this: School Name Test Score Students in Grade 11 Students in Grade 12 PS 1 Advanced 170 106 PS 1 Basic 87 53 PS 2 Advanced 141 120 PS…
FJJ
  • 37
  • 4
1
vote
2 answers

pivot_longer while keeping many paired columns

I've looked at several solutions on here but they don't work for me and I don't quite understand how to vary them. I have a very wide data structure, which looks like this (but even wider): Key Metadata Var1 Var1_remark Var2 Var2_remark…
1
vote
0 answers

Excel/Google Sheets: Looking up multiple values from a master sheet

I have a few questions about a sample spreadsheet that I've edited for your viewing here: https://docs.google.com/spreadsheets/d/14LSODtDZNTkfaVoB7lBmJKNeCx8ZKwIPnUwdwwgV0x4/. I'll start with the right-most tab and work my way left, but to save time…
1
vote
1 answer

Office Scripts Sorting a Pivot Table

I have an Office Script that creates a Pivot Table. The last thing I would like to do is sort the pivot table on the same column values I filtered. Scripts doesn't record this action and I am not finding any examples. I do not understand how to…
JSP
  • 35
  • 5
1
vote
2 answers

How to remove index marks from the x axis in python plot()?

I manage to create a graph using plot() on a certain pivot_table(). The problem is that the x axis indexes are to busy so you can't really read them (I added a picture). Here is what i wrote: import pandas as pd import matplotlib.pyplot as…
1
vote
0 answers

How to pivot some column in Redshift and append to the table?

I have a table like create temp table x ( id integer, date date, month integer, cost integer); insert into x values (1, '2022-09-01', 1, 5), (1, '2022-09-01', 2, 20), (1, '2022-09-01', 3, 33), (1, '2022-09-01', 4,…
Raksha
  • 1,572
  • 2
  • 28
  • 53
1
vote
0 answers

Correct Subtotals for % amount in in pivot table

Could i get your help on some report please? Actually I have developed some report where I have used pivot table for getting Subtotals of each column by using the following code: It gives the Sum for each columns but the problem is that i'm also…
Ahmed
  • 11
  • 4
1
vote
2 answers

Using crosstab with dynamic number of columns

I have a table with data: create Table ProductSales ( Productname varchar(50), Year int, Sales int ); Insert into ProductSales values ('A', 2017, 100), ('A', 2018, 150), ('A', 2019, 300), ('A', 2020, 500), …
1
vote
3 answers

Normalize the table by changing some rows in to Column

Below sample table has a Section with Questions and the possible answers that each questions can have, all in the single row.. Each question can have between 1 to 4 answers. Sec Name Question Text Answer 1 Answe1 Autofail Answer 1 Score Answer…
user4912134
  • 1,003
  • 5
  • 18
  • 47
1
vote
4 answers

pivot wider but keep repeating the index

I have a dataframe in pandas of the sort df = pd.DataFrame({ "id": [1, 1, 1, 1, 2, 2, 2, 2], "column": ["a", "b","a", "b", "a", "b", "a", "b"], "value": [1, 7, 6, 5, 4, 3, 1, 7] }) I want to generate a new dataframe where we…
Nikola
  • 620
  • 2
  • 5
  • 18
1
vote
0 answers

Excel pivot table slicer selection to show all pivoted columns, not only the intersection for the selected value

I want to apply a slicer for the value and show only the item where this value exists, but also show all values related to this item. Here is the sample data and the result when the value 100 is selected: Sample data and result Here is the result…
dgi
  • 11
  • 1
1
vote
1 answer

PostgreSQL Crosstab Query: return and sql tuple descriptions are incompatible

I have a query that should pivot a table with large number of values in a certain column that should be transformed into the column names of the pivoted table, i.e., SELECT * FROM crosstab( $$SELECT user_id, item_id, rating FROM tbl …
Marina
  • 330
  • 1
  • 6
  • 15
1
vote
1 answer

Creating a pivot table with multiple columns

I'm trying to create a pivot table with multiple columns; I'm unsure how to explain this better. But the following is the desired output, dataframe setup, and code I have tried so far. Desired Output: Dataframe Setup: data = { 'WholesalerID': {0:…
M J
  • 379
  • 2
  • 8
1
vote
1 answer

EPPlus 6.x - Show/Hide Pivot Table Field List (hidePivotFieldList="1")

EPPlus version: 6.1.0, .NET Core 7, C# Is there a way to hide the Pivot Table Field List? I couldn't find any existing methods to accomplish this. I have added a Macro to accomplish this behaviour, however the user experience is poor as they have…
MHop
  • 3,053
  • 3
  • 17
  • 13
1
vote
1 answer

How to format and color monetary numbers in Pandas dataframe?

I'm trying to apply formatting to a pandas pivot table so that it has color formatting and number formatting with commas, no decimals, $ in front of the number and parenthesis for negatives. import numpy as np import pandas as pd money =…
tonytone
  • 71
  • 1
  • 11
1 2 3
99
100