transpose

Python pandas convert rows to columns where multiple columns exist [duplicate]

痞子三分冷 提交于 2020-01-01 16:42:16
问题 This question already has answers here : how to unstack (or pivot?) in pandas (3 answers) Closed 2 years ago . I have a DF with multiple columns which I want to convert from rows to columns most solutions I have seen on stack overflow only deal with 2 columns From DF PO ID PO Name Region Date Price 1 AA North 07/2016 100 2 BB South 07/2016 200 1 AA North 08/2016 300 2 BB South 08/2016 400 1 AA North 09/2016 500 To DF PO ID PO Name Region 07/2016 08/2016 09/2016 1 AA North 100 300 500 2 BB

How can I transpose my dataframe so that the rows and columns switch in r?

最后都变了- 提交于 2019-12-31 04:38:31
问题 I have a dataframe (simplified) that looks like this: Age, Kodiak, Banana, Banff, Montreal, Fairfax Age_1, 5, 6 , 7, 9, 2 Age_2, 7, 6, 4, 3, 2 Age_3, 5, 3, 8, 5, 9 I would like my dataframe to look more like this: Location, Age_1, Age_2, Age_3 Kodiak, 5, 7, 5 Banana, 6, 6, 3 Banff, 7, 4, 8 Montreal, 9, 3, 5 Fairfax, 2, 2, 9 I've looked at the transpose function but I'm a bit confused on how to switch both the columns and rows. I'm very new to R. 回答1: There are two ways you can do this. The

Query one table and output data into multiple columns

半城伤御伤魂 提交于 2019-12-31 04:28:30
问题 Simply put I am trying to take a single column query result and output it into a 5 wide by × long table. This is how the main table is organized. On separate tabs, I want to list all of the caught and seen Pokemon on their own for easy search. While I can get it to output something like this with =query(NatDex, "Select C Where F <> ''",1) I would like it to output the data something like this for easy reading so it's not eventually 100+ entries long: Bonus points if you can give me formula

transpose matrix R

两盒软妹~` 提交于 2019-12-30 07:15:26
问题 I have a data frame in R that I want to transpose into a different format, please see the example below: Can I use the transpose function in R? Input data frame: Samples A1 A2 A3 B1 B2 B3 Sample1 123 123 321 32 321 32132 Sample2 12321 32321 2321 2313 3213 3123 Sample3 454 54 543 543 43 435 Desired Output: Samples 1 2 3 Sample1 A 123 123 321 Sample1 B 32 321 32132 Sample2 A 12321 32321 2321 Sample2 B 2313 3213 3123 Sample3 A 454 54 543 Sample3 B 543 43 435 回答1: To give some props to base R,

jQuery to transpose HTML table with header and footer

余生长醉 提交于 2019-12-29 09:12:47
问题 I need to transpose an HTML table (swap rows and columns). I found numerous jQuery plugins but they are more than what I need. I adapted some neat jQuery code from this stack but it does not work on tables that include thead and tfoot elements. function tableTransform(objTable) { objTable.each(function () { var $this = $(this); var newrows = []; $this.find("tr").each(function () { var i = 0; $(this).find("td").each(function () { i++; if (newrows[i] === undefined) { newrows[i] = $("<tr></tr>")

Matrix multiplication in scheme, List of lists

不羁岁月 提交于 2019-12-29 09:05:15
问题 I started to study Scheme and I do not understand some of it. I'm using DrRacket. I wrote the following code: (define mult_mat (λ (A B) (Trans_Mat (map (λ (x) (mul_Mat_vec A x)) (Trans_Mat B))))) That uses this functions: (define Trans_Mat (λ (A) (apply map (cons list A)))) (define mul_Mat_vec (λ (A v) (map (λ (x) (apply + (map * x v))) A))) In mult_mat , I multiply the matrix A in each vector of the transpose matrix B. It works fine. I found a code on the web that makes the multiplication in

Matrix multiplication in scheme, List of lists

折月煮酒 提交于 2019-12-29 09:05:10
问题 I started to study Scheme and I do not understand some of it. I'm using DrRacket. I wrote the following code: (define mult_mat (λ (A B) (Trans_Mat (map (λ (x) (mul_Mat_vec A x)) (Trans_Mat B))))) That uses this functions: (define Trans_Mat (λ (A) (apply map (cons list A)))) (define mul_Mat_vec (λ (A v) (map (λ (x) (apply + (map * x v))) A))) In mult_mat , I multiply the matrix A in each vector of the transpose matrix B. It works fine. I found a code on the web that makes the multiplication in

Is there a way to transpose data in Hive?

随声附和 提交于 2019-12-28 06:54:06
问题 Can data in Hive be transposed? As in, the rows become columns and columns are the rows? If there is no function straight up, is there a way to do it in a couple of steps? I have a table like this: | ID | Names | Proc1 | Proc2 | Proc3 | | 1 | A1 | x | b | f | | 2 | B1 | y | c | g | | 3 | C1 | z | d | h | | 4 | D1 | a | e | i | I want it to be like this: | A1 | B1 | C1 | D1 | | x | y | z | a | | b | c | d | e | | f | g | h | i | I have been looking up other related questions and they all

Build adjacency matrix from list of weighted edges in BigQuery

寵の児 提交于 2019-12-25 08:05:04
问题 Related issue: How to create dummy variable columns for thousands of categories in Google BigQuery I have a table of list of weighted edges which is a list of user-item rating, it looks like this: | userId | itemId | rating | 001 | 001 | 5.0 | 001 | 002 | 4.0 | 002 | 001 | 4.5 | 002 | 002 | 3.0 I want to convert this weighted edge list into a adjacency matrix: | userId | item001 | item002 | 001 | 5.0 | 4.0 | 002 | 4.5 | 3.0 According to this post, we can do it in two steps, the first step is

How transpose a table using SQL?

霸气de小男生 提交于 2019-12-25 06:55:04
问题 I have a table like this: id | P | C | A | B -------------------- 1 |100 |3 |a1 | b1 2 |101 |3 |a2 | b2 3 |102 |3 |a3 | b3 4 |103 |3 |a4 | b4 5 |100 |4 |a5 | b5 6 |101 |4 |a6 | b6 7 |102 |4 |a7 | b7 8 |103 |4 |a8 | b8 I want to get a new transposed structure like this: P |_3A | _3B |_4A | _4B ------------------------- 100 | a1 | b1 | a5 | b5 101 | a2 | b2 | a6 | b6 102 | a3 | b3 | a7 | b7 103 | a4 | b4 | a8 | b8 As you can see ,new field names have been extracted from C field in the original