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

How to create a pivot table from hstore data?

Imagining I have a table cars with a field data inside: CARS name | data car 1 | { "doors" => "5", "engine" => "1.1" } car 2 | { "doors" => "3", "engine" => "1.1", "air_conditioning" => "true" } car 3 | { "doors" => "5", "engine" => "1.4"…
Gustavo Semião-Lobo
  • 2,468
  • 3
  • 18
  • 26
5
votes
2 answers

Pandas Crosstab: Change Order of Columns That Are Named as Formatted Dates (mmm yy)

I have been looking for how to order columns for pandas crosstabs to no avail. I specifically need to order my columns which are formatted dates (mmm yy) based on the values of the dates and not sorted alphabetically on the the 3-letter name of…
Stacy L. Gardner
  • 561
  • 1
  • 4
  • 12
5
votes
2 answers

How can I PIVOT TABLE Or CrossTab By Datetime?

I need crosstab or pivot table By select Datetime. Table filesTA EmpNo ChkDate ChkIn 00001 2012-10-10 00:00:00.000 2012-10-10 07:22:00.000 00002 2012-10-10 00:00:00.000 2012-10-10 07:30:00.000 00001 …
nettoon493
  • 17,733
  • 7
  • 30
  • 45
4
votes
1 answer

How to create a confusion matrix containing multiple judgments in R?

I've got a data set from two raters judging a set of videoclips on multiple (binary) criteria. I'd like to plot a confusion matrix to better understand their agreement/disagreement. But all the examples I've found so far are for cases where each…
anthill
  • 43
  • 4
4
votes
1 answer

MySQL dynamic cross tab

I have a table like this: way stop time 1 1 00:55 1 2 01:01 1 3 01:07 2 2 01:41 2 3 01:47 2 5 01:49 3 1 04:00 3 2 04:06 3 3 04:12 and…
Paolo Cesari
  • 51
  • 1
  • 5
4
votes
1 answer

How to pivot a Key/Value style table into a normal table in MySQL

I am trying to convert the following table into something the is a bit easier to query. The historical data is important so it cannot get thrown away and there is an indefinite number of options for Variable (I only need some of them in the final…
4
votes
1 answer

Crosstab Sorting in JasperReports

I have a column group in a Crosstab that is a String. It uses the field SectionName. There is another field, SectionID (Integer), that I want to sort by. I put $F{SectionID} in the Sort By Expression but I get the…
Allan
  • 2,889
  • 2
  • 27
  • 38
4
votes
1 answer

Postgres Transpose Rows to Columns Based on Column Value

I have the following statement table in Postgres: stock | year | statement | amount ACME | 2003 | Q1 Earnings | 100 ACME | 2003 | Q2 Earnings | 200 ACME | 2004 | Q2 Earnings | 300 How do I make a new table with all of a…
user2415706
  • 932
  • 1
  • 7
  • 19
4
votes
2 answers

Cross Tabulation with R Markdown

I have struggle creating a simple nice looking cross tabulation for a PDF knitted R Markdown document. I have a data set that is similar to this example: library(tidyverse) fakeData <- tibble(id = c(1,2,3,4,5,6,7,8,9,10), bmi =…
ludo
  • 169
  • 1
  • 12
4
votes
1 answer

postgresql Cross Tab syntax error: No function matches the given name and argument types. You might need to add explicit type casts

I am trying to create a cross tab, but it is giving me an error: No function matches the given name and argument types. You might need to add explicit type casts. Here is my query for creating a cross tab: CREATE TABLE regions_ct(region_id SERIAL,…
Nathan Bell
  • 167
  • 1
  • 14
4
votes
4 answers

Pivot table with multiple value columns

I have a Postgres table with products data from different manufacturers, here the simplified table structure: CREATE TABLE test_table ( sku text, manufacturer_name text, price double precision, stock …
Vlad
  • 348
  • 3
  • 10
4
votes
4 answers

tidyverse: Cross tables of one variable with all other variables in data.frame

I want to make cross table of a variable with all other variables in the data.frame. library(tidyverse) library(janitor) humans <- starwars %>% filter(species == "Human") humans %>% janitor::tabyl(gender, eye_color) gender blue blue-gray…
MYaseen208
  • 22,666
  • 37
  • 165
  • 309
4
votes
5 answers

How to pivot or crosstab in postgresql without writing a function?

I have a dataset that looks something like this: I'd like to aggregate all co values on one row, so the final result looks something like: Seems pretty easy, right? Just write a query using crosstab, as suggested in this answer. Problem is that…
samthebrand
  • 3,020
  • 7
  • 41
  • 56
4
votes
2 answers

Concatenate strings for matrix from two tables

I have 3 tables in my PostgreSQL database, implementing a many-to-many relationship: droit, role and role_droit. See diagram in the attached image. I have this query to return the current result (also in the image): SELECT matrix_view.droit_id, …
djorgue
  • 55
  • 3
4
votes
1 answer

Crosstab Dataframe with resampled datetime from table file

Given a file like this: date uselessinfo category uselessinfo2 2011-07-22 02:56:36 banana 1 apple 2011-02-27 17:15:44 banana 4 apple 2010-12-12 00:13:42 banana 1 apple 2010-10-12 00:13:00 banana 2 apple I am using pandas to build…
Vanpourix
  • 185
  • 7