transpose

Postgres - Transpose Rows to Columns

不羁的心 提交于 2019-11-26 22:03:28
I have the following table, which gives multiple email addresses for each user. I need to flatten this out to columns on a user query. To give me the "newest" 3 email addresses based on the creation date. user.name | user.id | email1 | email2 | email3** Mary | 123 | mary@gmail.com | mary@yahoo.co.uk | mary@test.com Joe | 345 | joe@gmail.com | [NULL] | [NULL] Erwin Brandstetter Use crosstab() from the tablefunc module. SELECT * FROM crosstab( $$SELECT user_id, user_name, rn, email_address FROM ( SELECT u.user_id, u.user_name, e.email_address , row_number() OVER (PARTITION BY u.user_id ORDER BY

Excel: Formulas for converting data among column / row / matrix

ε祈祈猫儿з 提交于 2019-11-26 21:52:06
Are there formulas to convert data in a column to a matrix or to a row? And to convert from/to other combinations? What about an even more complex case: reshape a matrix of width W to width N*W? There are a few similar or related questions. I have answered some of them, marked with *. I keep updating this list, as new similar (or equal) questions are added: Formatting Data: Columns to Rows * Move content from 1 column to 3 columns * how to split one column into two columns base on conditions in EXCEL * writing a macro to transpose 3 columns into 1 row Excel VBA transpose with characters

What is the fastest way to rotate the bits in an 8x8 block on bits?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 20:43:32
问题 I'm not sure the exact term for what I'm trying to do. I have an 8x8 block of bits stored in 8 bytes , each byte stores one row. When I'm finished, I'd like each byte to store one column. For example, when I'm finished: Byte0out = Byte0inBit0 + Byte1inBit0 + Byte2inBit0 + Byte3inBit0 + ... Byte1out = Byte0inBit1 + Byte1inBit1 + Byte2inBit1 + Byte3inBit1 + ... What is the easiest way to do this in C which performs well? 回答1: This code is cribbed directly from "Hacker's Delight" - Figure 7-2

Use a dope vector to access arbitrary axial slices of a multidimensional array?

匆匆过客 提交于 2019-11-26 17:20:02
问题 I'm building a suite of functions to work with a multidimensional-array data structure and I want to be able to define arbitrary slices of the arrays so I can implement a generalized inner product of two arbitrary matrices (aka Tensors or n-d arrays ). An APL paper I read (I honestly can't find which -- I've read so many) defines the matrix product on left-matrix X with dimensions A;B;C;D;E;F and right-matrix Y with dimensions G;H;I;J;K where F==G as Z <- X +.× Y Z[A;B;C;D;E;H;I;J;K] <- +/ X

SQL Server 2008 Vertical data to Horizontal

时光毁灭记忆、已成空白 提交于 2019-11-26 16:59:44
问题 I apologize for submitting another question on this topic, but I've read through many of the answers on this and I can't seem to get it to work for me. I have three tables I need to join and pull info on. One of the tables is only 3 columns and stores the data vertically. I would like to transpose that data to a horizontal format. The data will look like this if I just join and pull: SELECT a.app_id, b.field_id, c.field_name, b.field_value FROM table1 a JOIN table2 b ON a.app_id = b.app_id

MySql Transpose Row into Column and Column into Row [duplicate]

懵懂的女人 提交于 2019-11-26 16:57:01
问题 This question already has answers here : How can I return pivot table output in MySQL? (8 answers) Closed 6 years ago . i have problem with transposing row to column and column to row. I can do that if it just transpose row to column or column to row. This my table with data UNIT|JAN|FEB|MAR|APR|MEI|JUN CS-1|100|200|300|400|500|600 CS-2|111|222|333|444|555|666 CS-3|331|123|423|923|918|123 and I would like to get the following output MONTH|CS-1|CS-2|CS-3 JAN |100 |111 |331 FEB |200 |222 |123

SQL: Real Transpose

隐身守侯 提交于 2019-11-26 16:56:23
问题 I know about pivot and unpivot. That is not what I want. Pivot and unpivot aggregate data, but that is not what I want. Think of a table as a matrix (linear algebra). If I start with an m x n matrix, I want to convert that matrix (table) into an n x m matrix. I want a true TRANSPOSE. How can I do this in SQL? For example if I have: 1 2 3 1 2 4 6 7 8 3 2 1 3 9 1 then the result should be: 1 1 6 3 3 2 2 7 2 9 3 4 8 1 1 Notice that the number of rows becomes the number of columns, and vice versa

Matrix expression causes error “requires numeric/complex matrix/vector arguments”?

蹲街弑〆低调 提交于 2019-11-26 16:49:39
问题 ma=diag(3)+t(da)%*%da R Code above, error message as follows: Error in t(da) %*% da : requires numeric/complex matrix/vector arguments da is a matrix, looks as following: V45 V46 V47 V48 V49 V50 V51 1 0.461727059 2.357732985 -1.536932071 -1.34425710 0.893541975 -0.0676913075 -0.86532231 2 0.253022555 1.524473647 -0.588911138 -1.65207275 -0.072255170 -0.5212951533 -1.43686625 3 0.824678362 1.497001189 0.335973892 -0.84027799 0.275289411 -0.2921928001 -0.16277595 4 0.854530787 2.258305198 0

Convert column to row in Python Pandas

老子叫甜甜 提交于 2019-11-26 12:27:08
问题 I have the following Python pandas dataframe: fruits | numFruits --------------------- 0 | apples | 10 1 | grapes | 20 2 | figs | 15 I want: apples | grapes | figs ----------------------------------------- Market 1 Order | 10 | 20 | 15 I have looked at pivot(), pivot_table(), Transpose and unstack() and none of them seem to give me this. Pandas newbie, so all help appreciated. 回答1: You need set_index with transpose by T: print (df.set_index('fruits').T) fruits apples grapes figs numFruits 10

How to transpose rows to columns with large amount of the data in BigQuery/SQL?

回眸只為那壹抹淺笑 提交于 2019-11-26 11:39:22
问题 I have a problem in transposing a large amount of data table in BigQuery (1.5 billion rows) from rows to columns. I could figure out how to do it with small amount of data when hardcoded, but with this large amount. A snapshot of the table looks like this: +--------------------------+ | CustomerID Feature Value | +--------------------------+ | 1 A123 3 | | 1 F213 7 | | 1 F231 8 | | 1 B789 9.1 | | 2 A123 4 | | 2 U123 4 | | 2 B789 12 | | .. .. .. | | .. .. .. | | 400000 A123 8 | | 400000 U123 7