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
6
votes
1 answer

Problem with fetching data from database in Laravel

I have a search form to list properties/ads through certain criteria. I am trying to fetch all properties based on offer or demand, depending on what is clicked in the form. I have three tables properties (id, price, location) properties_categories…
rose
  • 447
  • 5
  • 18
6
votes
1 answer

Save pandas pivot_table to include index and columns names

I want to save a pandas pivot table for human reading, but DataFrame.to_csv doesn't include the DataFrame.columns.name. How can I do that? Example: For the following pivot table: >>> import pandas as pd >>> df = pd.DataFrame([[1, 2, 3], [6, 7,…
Cai
  • 1,726
  • 2
  • 15
  • 24
6
votes
2 answers

Can I create a custom summary field in Excel 2007 pivot table?

Is there anyways to create a custom "summarize value field by" function to be used in an XL 2007 pivot table. The standard Sum, Count, Average, Max, etc. are not sufficient for me. I would accept a solution in VBA, or a solution that requires an…
Suraj
  • 35,905
  • 47
  • 139
  • 250
6
votes
1 answer

Dask how to pivot DataFrame

I am using the code below but get an error after pivoting the DataFrame: dataframe: name day value time 0 MAC000002 2012-12-16 0.147 09:30:00 1 MAC000002 2012-12-16 0.110 10:00:00 2 MAC000002 2012-12-16 0.736 …
proximacentauri
  • 1,749
  • 5
  • 25
  • 53
6
votes
1 answer

Pivot table with count as aggfunc gives different result than value_counts

I am working with some data and end up with a situation where I want to cut a series like this: df = pd.DataFrame({'A': 10000*[1], 'B': np.random.randint(0, 1001, 10000)}) df['level'] = pd.cut(df.B, bins = [0, 200, 400, 600, 800, 1000], …
6
votes
1 answer

How to populate pivot table in laravel??

I wrote factories for posts and categories and the work perfectly. But i can't find a way to populate the category_post table to test the ManyToMany relation between them. How can I do that?
Rahimi0151
  • 395
  • 3
  • 11
6
votes
4 answers

Report connections for Pivot table slicer doesn't show all pivot tables?

I have 3 sheets with several pivot tables on each and one sheet with the source data. These 4 sheets were copied directly from another workbook. When I copied the worksheets over the source data for each pivot table was still the original source…
Sorath
  • 543
  • 3
  • 10
  • 32
6
votes
1 answer

Create Pivot Table using Openpyxl

Is there a way we can create pivot table in Excel using openpyxl library? I saw old threads mentioning its not possible, but I saw some documentation about creating one on below…
Parth Karia
  • 265
  • 1
  • 4
  • 11
6
votes
2 answers

How to pivot one column containing strings in a dataframe?

I am trying to reshape a pandas dataframe, by turning one of the columns in the data, into rows (by pivoting or unstacking). I am new to this, so likely that I'm missing something obvious. I've searched extensively, but have not been able to…
brendxn
  • 73
  • 1
  • 5
6
votes
3 answers

python pivot table of counts

I have a dataframe df as follows: | id | movie | value | |----|-------|-------| | 1 | a | 0 | | 2 | a | 0 | | 3 | a | 20 | | 4 | a | 0 | | 5 | a | 10 | | 6 | a | 0 | | 7 | a | 20 | | 8 | b…
Symphony
  • 1,655
  • 4
  • 15
  • 22
6
votes
2 answers

Add columns to pivot table with pandas

I have the table as follow: import pandas as pd import numpy as np #simple table fazenda = [6010,6010,6010,6010] quadra = [1,1,2,2] talhao = [1,2,3,4] arTotal = [32.12,33.13,34.14,35.15] arCarr = [i/2 for i in arTotal] arProd = [i/2 for i in…
Franklin Januário
  • 125
  • 2
  • 2
  • 7
6
votes
1 answer

Pandas pivot_table group column by values

I am trying to use numeric values as columns on a Pandas pivot_table. The problem is that since each number is mostly unique, the resulting pivot_table isn't very useful as a way to aggregate my data. Here is what I have so far (fake data…
Bruno Vieira
  • 151
  • 4
  • 9
6
votes
2 answers

Apache POI - Expand All / Collapse All

I am now working on Apache POI to create an excel from Java, where I need to have Expand/Collapse All in the exported excel. Please find the below images I want before and after expand, and the below code so far I tried. (It may need required jar,…
SK.
  • 1,390
  • 2
  • 28
  • 59
6
votes
1 answer

Is There Complete Overlap Between `pd.pivot_table` and `pd.DataFrame.groupby` + `pd.DataFrame.unstack`?

(Please note that there's a question Pandas: group by and Pivot table difference, but this question is different.) Suppose you start with a DataFrame df = pd.DataFrame({'a': ['x'] * 2 + ['y'] * 2, 'b': [0, 1, 0, 1], 'val': range(4)}) >>> df Out[18]:…
Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
6
votes
3 answers

Add columns to a pivot table (pandas)

I know in R I can use tidyr for the following: data_wide <- spread(data_protein, Fraction, Count) and data_wide will inherit all the columns from data_protein that are not spread. Protein Peptide Start Fraction Count 1 A 122 …
Nico
  • 311
  • 4
  • 11