Questions tagged [crosstab]

A cross tab, also known as 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 also include the relevant language tag (python, R, sql-server etc.) on your question.

Resources:

1549 questions
3
votes
2 answers

Display fields in a row

I have a multi select query SELECT C.CATEGORIES_NAME FROM CATEGORIES AS C WHERE CATEGORIES_ID = 1 UNION SELECT L.LOCATION_TYPE_NAME FROM LOCATIONS_TYPE AS L WHERE LOCATION_TYPE_ID = 2 UNION SELECT S.SUBSCRIPTION_TYPE FROM SUBSCRIPTIONS AS…
MegaRoks
  • 898
  • 2
  • 13
  • 30
3
votes
1 answer

Stretching a CrossTab's Cell Horizontally

How would I get a value cell [in a CrossTab widget] to stretch horizontally, rather than vertically? Stretch on overflow stretches the cell vertically, rather than horizontally.
monksy
  • 14,156
  • 17
  • 75
  • 124
3
votes
2 answers

How to transpose pandas dataframe to cross-tabulate dataframe keeping all values

Let's suppose we have such dataframe: df = pd.DataFrame({'key' : ['one', 'two', 'three', 'four'] * 3, 'col' : ['A', 'B', 'C'] * 4, 'val1' : np.random.randn(12), 'val2' : np.random.randn(12), …
Rocketq
  • 5,423
  • 23
  • 75
  • 126
3
votes
0 answers

Any Lib or help to create the crosstab?

I am trying to develop a simple crosstab application using postgreSQL and .netcore. I need suggestion to get if any lib exists to provide the basic crosstab functions. May be a method where I will pass Rows, Columns and it will retun the response…
3
votes
1 answer

postgres crosstab, ERROR: The provided SQL must return 3 columns

Hello I have created a view, but want to pivot it. OUTPUT before pivoting: tag1 | qmonth1 | qmonth2 | sum1 --------+-----------+-----------+-------- name1 | 18-05 | MAY | -166 name2 | 18-05 | MAY | -86 name3 | …
michal
  • 327
  • 4
  • 15
3
votes
1 answer

PostgreSQL multiple row as columns

I have a table like this: | id | name | segment | date_created | question | answer | |----|------|---------|--------------|----------|--------| | 1 | John | 1 | 2018-01-01 | 10 | 28 | | 1 | John | 1 | 2018-01-01 | 14 …
Joel
  • 974
  • 2
  • 10
  • 18
3
votes
1 answer

How to concatenate crosstabs when reading in a for loop in pandas

I am using Pandas module in python 3.5 to read crosstabs recursively from sub-directories and I want to concatenate the crosstabs inside the for loop after I call pd.crosstab() and after the for loop write the output to an excel file. I tried…
Sikander Waheed
  • 85
  • 1
  • 1
  • 4
3
votes
1 answer

How to use PL/pgSQL to construct a table with dynamic columns

I have a Postgres tabled called locations. It has a few million rows with data in the following format id | location_a | location_b ----+--------------+-------------- 36 | Sydney | London 37 | Atlanta | London 38 | New York |…
user2490003
  • 10,706
  • 17
  • 79
  • 155
3
votes
3 answers

Getting each element in Pandas crosstab

I have a dataset given below: a,b,c 1,1,1 1,1,1 1,1,2 2,1,2 2,1,1 2,2,1 I created crosstab with pandas: cross_tab = pd.crosstab(index=a, columns=[b, c], rownames=['a'], colnames=['b', 'c']) my crosstab is given as an output: b 1 2 c …
user3104352
  • 1,100
  • 1
  • 16
  • 34
3
votes
3 answers

PostgreSQL query with dynamic number of columns

I am trying to find a method to return a record set with a dynamic number of columns. I can write one query that will produce the list of column names I need as such: SELECT DISTINCT name FROM tests WHERE group = 'basic'; This will return a short…
penguin359
  • 1,289
  • 13
  • 26
3
votes
1 answer

How to remove hidden fields in tableau sheet while exporting as cross tab from tableau server?

I am using Tableau Desktop & Server 9.3. I have created field named as 'Sales'. There are many other measures and dimensions have been included in sheet along with field 'Sales'. But for some reasons I've to hide 'Sales' field. I've done this by…
IT Professional
  • 67
  • 1
  • 1
  • 8
3
votes
1 answer

Using crosstab on a query with a composite key (multiple columns)

I recently switched from SQL Server to PostgreSQL and trying to find equivalent of pivot function. I am not able to get a desired output using crosstab which I was able to achieve using SQL Server. Sample data. CREATE TABLE loc AS SELECT location,…
3
votes
2 answers

Cross tabs - need to aggregate several columns based on certain values in other columns

My data looks like this, all columns with binary presence/absence data: POP1 POP2 POP3 T1 T2 T3 T4 T5 T6 T7 T8 T9 1 1 0 1 1 1 1 0 1 0 0 1 1 0 1 0 1 …
Dag
  • 569
  • 2
  • 5
  • 20
3
votes
2 answers

Count occurrences in DataFrame

I've a Dataframe in this format: | Department | Person | Power | ... | |------------|--------|--------|-----| | ABC | 1234 | 75 | ... | | ABC | 1235 | 25 | ... | | DEF | 1236 | 50 | ... | | DEF | 1237 …
Gerrit
  • 2,515
  • 5
  • 38
  • 63
3
votes
3 answers

Processing/Transposing Pandas Dataframe

I got the following pandas dataframe: Id Category 1 type 2 1 type 3 1 type 2 2 type 1 2 type 2 I need to process and transpose the above data frame to: Id Category_type_1 Category_type_2 Category_type_3 1 0 …
iLoeng
  • 434
  • 1
  • 4
  • 14