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
24
votes
10 answers

How to change pivot table data source in Excel?

I want to change it from one database to another. There don't appear to be any options to do this on the pivot table context menu
adolf garlic
  • 3,034
  • 7
  • 39
  • 54
24
votes
3 answers

How to reverse a 2-dimensional table (DataFrame) into a 1 dimensional list using Pandas?

I am looking in Python/Pandas for a tip that reverses a 2-dimension table into 1 dimensional list. I usually leverage an Excel function to do it, but I believe that there is a smart Python way to do it. Step More details of the Excel…
Ning Chen
  • 712
  • 2
  • 7
  • 11
24
votes
9 answers

Use Excel pivot table as data source for another Pivot Table

I have a Pivot table in excel that is using a raw table as its data source. This pivot table is doing a bunch of grouping and summing of rows. I'd like to now use the result of this new pivot table as the data source for a new pivot table which…
Jonathan
  • 1,498
  • 2
  • 20
  • 41
22
votes
2 answers

pandas pivot table rename columns

How to rename columns with multiple levels after pandas pivot operation? Here's some code to generate test data: import pandas as pd df = pd.DataFrame({ 'c0': ['A','A','B','C'], 'c01': ['A','A1','B','C'], 'c02': ['b','b','d','c'], …
muon
  • 12,821
  • 11
  • 69
  • 88
22
votes
10 answers

Changing the Date Format for GROUPED dates in a PIVOT TABLE

I'm working in Excel 2010 Let's say you have a legitimate date field in your raw data with dates such as 1/1/2015. Then you create a pivot table with your date field in the row labels. Now assume you want to show results by month, so you right click…
ChrisG
  • 1,230
  • 4
  • 17
  • 35
22
votes
1 answer

How to create a pivot table on extremely large dataframes in Pandas

I need to create a pivot table of 2000 columns by around 30-50 million rows from a dataset of around 60 million rows. I've tried pivoting in chunks of 100,000 rows, and that works, but when I try to recombine the DataFrames by doing a .append()…
PTTHomps
  • 1,477
  • 2
  • 22
  • 38
22
votes
6 answers

Count Unique values with a condition

In column A I have list of different names. In column B, I have values either 0 or 1. I want to get a count of all the unique names from column A which have 1 in column B. Using below array formula I am able count unique names but not able to apply…
TechGeek
  • 2,172
  • 15
  • 42
  • 69
21
votes
5 answers

Pandas 'DataFrame' object has no attribute 'unique'

I'm working in pandas doing pivot tables and when doing the groupby (to count distinct observations) aggfunc={"person":{lambda x: len(x.unique())}} gives me the following error: 'DataFrame' object has no attribute 'unique' any ideas how to fix it?
jwzinserl
  • 427
  • 1
  • 3
  • 7
21
votes
3 answers

Convert values in a column to column headers in pandas

I have the following code, which takes the values in one column of a pandas dataframe and makes them the columns of a new data frame. The values in the first column of the dataframe become the index of the new dataframe. In a sense, I want to turn…
juniper-
  • 6,262
  • 10
  • 37
  • 65
21
votes
7 answers

PivotTable's Report Filter using "greater than"

I have a pivot table which has one of the fields (Probability) in a Report Filter. Its values are percentages in step of 5 (0,5,10,15,...,100). I'd like to use it to filter probabilities greater than or equal a certain value, but the filter only…
Lukasz
  • 557
  • 2
  • 13
  • 27
21
votes
4 answers

Using QUARTILE in an Excel pivot table to summarise data by sub-populations

I've got a large table of data in an Excel spreadsheet that, essentially, can be considered to be a collection of values for individuals identified as belonging to various subpopulations: IndivID SubPopID Value 1 A 33.56 …
Assad Ebrahim
  • 6,234
  • 8
  • 42
  • 68
20
votes
1 answer

Pandas Pivot Table manually sort columns

For a given data frame: UUT testa testb testc testd DateTime 2017-11-21 18:47:29 1.0 1.0 1.0 3.0 2017-11-21 18:47:30 1.0 2.0 1.0 4.0 2017-11-21 18:47:31 1.0 2.0 5.0…
user97662
  • 942
  • 1
  • 10
  • 29
20
votes
4 answers

Google Sheets Pivot Table Not Updating

I have a google app script which submits info to an organized sheet and would like to create a pivot table with the all information in the sheet. I can do this, but whenever I submit a new row of data to the sheet, it is not automatically included…
Ben
  • 279
  • 1
  • 3
  • 8
19
votes
6 answers

Convert X and Y arrays into a frequencies grid

I would like to convert two arrays (x and y) into a frequency n x n matrix (n = 5), indicating each cell the number of point that contains. It consists on resampling both variables into five intervals and count the existing number of points per…
Miguel Gonzalez
  • 706
  • 7
  • 20
19
votes
3 answers

How to remove multilevel index in pandas pivot table

I have a dataframe as given: df = {'TYPE' : pd.Series(['Advisory','Advisory1','Advisory2','Advisory3']), 'CNTRY' : pd.Series(['IND','FRN','IND','FRN']), 'VALUE' : pd.Series([1., 2., 3., 4.])} df = pd.DataFrame(df) df =…
Shivpe_R
  • 1,022
  • 2
  • 20
  • 31