transpose

Redshift. How can we transpose (dynamically) a table from columns to rows?

╄→гoц情女王★ 提交于 2019-12-10 18:25:32
问题 How can we transpose a Redshift table from columns to rows? For example, if we have a generic (not already known) table like the following: source table: date id alfa beta gamma ... omega 2018-08-03 1 1 2 3 4 2018-08-03 2 4 3 2 1 ... 2018-09-04 1 3 1 2 4 ... How we can achieve the following result? transposed table: date id column_name column_value 2018-08-03 1 alfa 1 2018-08-03 1 beta 2 ... 2018-08-03 2 omega 1 ... 2018-09-04 1 gamma 2 ... Where the target table, the number of columns (alfa,

Transpose DataFrame in Pandas while preserving Index column

流过昼夜 提交于 2019-12-10 15:35:52
问题 The problem is, when I transpose the DataFrame, the header of the transposed DataFrame becomes the Index numerical values and not the values in the "id" column. See below original data for examples: Original data that I wanted to transpose (but keep the 0,1,2,... Index intact and change "id" to "id2" in final transposed DataFrame) . DataFrame after I transpose, notice the headers are the Index values and NOT the "id" values (which is what I was expecting and needed) Logic Flow First this

Why does the transpose function change numeric to character in R?

我与影子孤独终老i 提交于 2019-12-10 12:48:24
问题 I've constructed a simple matrix in Excel with some character values and some numeric values (Screenshot of data as set up in Excel). I read it into R using the openxlsx package like so: library(openxlsx) data <- read.xlsx('~desktop/data.xlsx) After that I check the class: sapply(data, class) x1 a b c "character" "numeric" "numeric" "numeric" Which is exactly what I want. My problem occurs when I try to transpose the matrix, and then check for class again: data <- t(data) When i check with

CUDA In-place Transpose Error

懵懂的女人 提交于 2019-12-10 05:58:14
问题 I'm implementing a CUDA program for transposing an image. I created 2 kernels. The first kernel does out of place transposition and works perfectly for any image size. Then I created a kernel for in-place transposition of square images. However, the output is incorrect. The lower triangle of the image is transposed but the upper triangle remains the same. The resulting image has a stairs like pattern in the diagonal and the size of each step of the stairs is equal to the 2D block size which I

join tables and transpose columns and rows

心不动则不痛 提交于 2019-12-09 20:16:26
问题 I have one table that looks like this called survey_1: ================================================ |id | token | 1X2X1 | 1X2X2 | =====+========+===============+================| | 1 | 1 | YES | Justin Beiber | |----+--------+---------------+----------------| | 2 | 1 | YES | Britney Spears | |----+--------+---------------+----------------| note : 1X2X1 represents- survey-id X group-id X question-id I have another table called survey_questions: =============================================

how to transpose a matrix in r if the usual `t( )` doesn't work?

只谈情不闲聊 提交于 2019-12-09 16:41:16
问题 I have a matrix I am trying to transpose in R but the t() function does not return the right answer. How can I transpose the matrix? > xx=matrix(c(3,7,4,8),2,byrow=TRUE) > xx [,1] [,2] [1,] 3 7 [2,] 4 8 > t(xx) [1] 0.7071068 0.7071068 回答1: This answer is incorrect, but in ways that were enlightening to me and might be to others, so I'll leave it up. As @mnel noted, the base R function t() must be masked by another function of the same name. Try removing the function t() and doing t(xx) again.

How to transpose a 3D matrix?

对着背影说爱祢 提交于 2019-12-09 16:39:11
问题 I have a 3D matrix x_test of size (100, 33, 66) and I want to change its dimensions to (100, 66, 33) . What is the most efficient way to do this using python3.5? I look for something along those lines: y = x_test.transpose() 回答1: You can pass the desired dimensions to the function np.transpose using in your case np.transpose(x_test, (0, 2, 1)) . For example, import numpy as np x_test = np.arange(30).reshape(3, 2, 5) print(x_test) print(x_test.shape) This will print [[[ 0 1 2 3 4] [ 5 6 7 8 9]

SQL Transpose rows to columns (group by key variable)?

自作多情 提交于 2019-12-09 03:13:43
问题 I am trying to transpose rows into columns, grouping by a unique identifier (CASE_ID). I have a table with this structure: CASE_ID AMOUNT TYPE 100 10 A 100 50 B 100 75 A 200 33 B 200 10 C And I am trying to query it to produce this structure... | CASE_ID | AMOUNT1 | TYPE1 | AMOUNT2 | TYPE2 | AMOUNT3 | TYPE3 | |---------|---------|-------|---------|-------|---------|--------| | 100 | 10 | A | 50 | B | 75 | A | | 200 | 33 | B | 10 | C | (null) | (null) | (assume much larger dataset with large

How to get transpose of dynamic dataset for below sample input using Spark and Java

倾然丶 夕夏残阳落幕 提交于 2019-12-08 13:54:09
问题 I have one dataset and I want to transpose the columns (dynamic number of columns) into two rows always using Spark and Java. Sample input: +-------+-------+---------+ |titanic|IronMan|Juglebook| +-------+-------+---------+ | 101| test1| 10| | 102| test2| 20| | 103| test3| 30| +-------+-------+---------+ Sample Output: | Colname|colvalue +---------+----+----+---------+ | titanic| 101,102,103 | | IronMan | test1,test2,test3| |Juglebook | 10,20,30 | +-------+-------+-------------+ I tried with

Transpose / Pivot rows to columns

狂风中的少年 提交于 2019-12-08 12:00:04
问题 I am trying to transpose (Pivot?) a table. This is my current setup. Current Table: ID | Value 1 | 10 1 | 11 1 | 12 1 | 13 1 | 14 2 | 123 3 | 13423 3 | 1134 3 | 1234 Seeking the following result: ID | Value01 | Value 02 | Value 03 | Value 04 | Value 05 1 | 10 | 11 | 12 | 13 | 14 2 | 123 3 | 13423 | 1134 | 1234 Currently I am trying it with PIVOT however I am not completely sure how to PIVOT without a "category column" (such as days, or months). Could I use the ID column for this? SELECT ID,