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
2
votes
2 answers

Each rows to column values

I'm trying to create a view that shows first table's columns plus second table's first 3 records sorted by date in 1 row. I tried to select specific rows using offset from sub table and join to main table, but when joining query result is ordered…
Tuguldur
  • 31
  • 5
2
votes
1 answer

How can I get a record to be counted in multiple columns of a Crosstab Query?

Background information: My company requires employees to maintain at least one certification (cert) on a position. There are a total of 17 different certifications that an employee can get. An employee can hold multiple certs. But on any one day…
JRID
  • 23
  • 3
2
votes
1 answer

How to convert Rows to Columns in postgresql query

I have a simple query output of two rows and single column Virginia Texas I want the output as Virginia | Texas I just tried it as two subqueries in column list. select (select state from table where code='VA') as state1 (select state from…
suresh
  • 23
  • 3
2
votes
3 answers

How to calculate percentages for rows and columns in a cross-tab?

I have a 3 level contingency table for which I'm trying to calculate the percentages for each cell of the table as a function of the sum row total for each row and then a function of the sum column total for each column. Here is the data which I…
2
votes
1 answer

How to specify row and column names in a crosstable when both are categorical

I have two categorical variables and I am trying to create a cross tabulation for them. Since both values are yes and no , I want to specify the row and column names for ease of understanding. T4 <- table(bank$Term_deposit, bank$housing_loan) %>%…
analyst045
  • 628
  • 7
  • 21
2
votes
1 answer

table function result in R with three variables in Python pandas

Let's say we have this sample data. | mem_id | main_title | sub_title | ----------------------------------- | 1 | 1 | 1 | | 10 | 3 | 2 | | 3 | 3 | 2 | | 45 | 1 | 2 …
jenna.h
  • 53
  • 1
  • 4
2
votes
2 answers

Join master table's data with key-value attributes form another table using keys as columns

I have a PostgreSQL table called Events like this: +----+----------+------------+ | id | event | created_at | +----+----------+------------+ | 1 | pageview | 2019-03-29 | +----+----------+------------+ | 2 | purchase | 2019-03-28…
2
votes
2 answers

Crosstab with Python with Sales data

I have this data: Date Month ProductCategory Sales 1/1/2009 2009-Jan Clothing 1755 1/1/2009 2009-Jan Grossery 524 1/1/2009 2009-Jan Toys 936 2/1/2009 2009-Feb Clothing …
rba
  • 77
  • 1
  • 2
  • 7
2
votes
0 answers

How to to display list of values in rowgroup in a crosstab?

I'm unable to display list of values in crosstab rowgroup I have this sample json { "header": { "columnName": [ "Product Store1", "location" ], "values": [{ "purchase": { …
Anjana
  • 109
  • 10
2
votes
0 answers

Concatenating crosstabs of different variables

I have a Pandas (0.23.4) DataFrame with several categorical columns. df = pd.DataFrame(np.random.choice([True, False, np.nan], (6,4)), columns = ['a','b','c','d']) a b c d 0 NaN 1.0 NaN NaN 1 NaN 1.0 NaN 0.0 2 1.0 NaN 1.0 …
perigon
  • 2,160
  • 11
  • 16
2
votes
2 answers

Using pandas crosstab to compute cross count on a category column

I have a table with customer purchasing product category. I am trying to build a cross-selling matrix counting the unique customer for each couple of product category, and have a total with unique count as well. pandas.crosstab is a good way to…
ant1j
  • 305
  • 2
  • 18
2
votes
1 answer

Cross-table for subset in R

I have the following data frame (simplified): IPET Task Type 1 1 1 1 2 2 1 3 1 2 1 1 2 1 2 How can I create a cross table (using the crosstable function in gmodels, because I need to do a chi-square test),…
user3315563
  • 495
  • 2
  • 5
  • 10
2
votes
1 answer

Returning null individual values with postgres tablefunc crosstab()

I am trying to incorporate the null values within the returned lists, such that: batch_id |test_name |test_value ----------------------------------- 10 | pH | 4.7 10 | Temp | 154 11 | pH | 4.8 11 …
user1644030
  • 251
  • 3
  • 10
2
votes
2 answers

python psycopg2 - ProgrammingError: function crosstab(unknown, unknown) does not exist

I would like to execute an SQL query which has crosstab function in Python, however I get this error message: psycopg2.ProgrammingError: function crosstab(unknown, unknown) does not exist HINT: No function matches the given name and argument…
Marina
  • 330
  • 1
  • 6
  • 15
2
votes
1 answer

Query with dynamic target columns

I am trying to build a view in Postgres that uses 3 tables worth of data. I am not sure if this is possible and have searched around a bit on google but didn't turn up anything conclusive. This is what I am attempting to do: I have a table of item…
NallaN
  • 23
  • 1
  • 4