transpose

Wide to long dataset using pandas

佐手、 提交于 2019-12-23 13:14:16
问题 There are a lot of questions out there with similar titles but I'm unable to solve the issues that I'm having with my dataset. Dataset: ID Country Type Region Gender IA01_Raw IA01_Class1 IA01_Class2 IA02_Raw IA02_Class1 IA02_Class2 QA_Include QA_Comments SC1 France A Europe Male 4 8 1 J 4 1 yes N/A SC2 France A Europe Female 2 7 2 Q 6 4 yes N/A SC3 France B Europe Male 3 7 2 K 8 2 yes N/A SC4 France A Europe Male 4 8 2 A 2 1 yes N/A SC5 France B Europe Male 1 7 1 F 1 3 yes N/A ID6 France A

Create object from array of keys and values

[亡魂溺海] 提交于 2019-12-23 12:45:22
问题 I've been banging my head against the wall for several hours on this and just can't seem to find a way to do this. I have an array of keys and an array of values, how can I generate an object? Input: [["key1", "key2"], ["val1", "val2"]] Output: {"key1": "val1", "key2": "val2"} 回答1: Resolved this on github: .[0] as $keys | .[1] as $values | reduce range(0; $keys|length) as $i ( {}; . + { ($keys[$i]): $values[$i] }) 回答2: The current version of jq has a transpose filter that can be used to pair

array transpose in scala

空扰寡人 提交于 2019-12-23 12:17:11
问题 I have 2 scala array and I would like to multiply them. val x = Array(Array(1,2),Array(3,4),Array(5,6),Array(7,8),Array(9,10),Array(11,12),Array(13,14),Array(15,16),Array(17,18),Array(19,20),Array(21,22)) val y = Array(2, 5, 9) I wish to get a Array.ofDim[Int](3, 2) like val z = Array(Array(1*2 + 3 *2 + 5*2 + 7*2... 2*2 + 4*2 + 6*2 + 8*2...,),Array(1*5 + 3*5 + 5*5 + 7*5... 2*5 + 4*5 + 6*5 + 8*5...,),Array(1*9 + 3 *9 + 5*9 + 7*9... 2*9 + 4*9 + 6*9 + 8*9...,) I tried to use x.transpose , then

How to transpose MySQL rows and repeat column headers?

随声附和 提交于 2019-12-23 10:26:50
问题 I have a mysql table that looks like: id group_id item_code item_label item_detail item_score 1 10 BLU123 Blue 123 Blah blah 123 3 2 10 BLU124 Blue 124 Blah blah 124 6 3 10 BLU125 Blue 125 Blah blah 125 2 Is there any sql statement that will output the table as: group_id item_code1 item_label1 item_detail1 item_score1 item_code2 item_label2 item_detail2 item_score2 item_code3 item_label3 item_detail3 item_score3 10 BLU123 Blue 123 Blah blah 123 3 BLU124 Blue 124 Blah blah 124 6 BLU125 Blue

Transpose / Pivot Rows to Columns in SQL Server

十年热恋 提交于 2019-12-23 06:04:39
问题 I have three tables - the first contains questions with a unique ID QID | Question ------------------ 1 | Question 1 2 | Question 2 3 | Question 3 4 | Question 4 5 | Question 5 The second contains answers to those questions, the unique ID from the first table and then an ID of the record that links the answers together QID | Answer | Parent ------------------------- 1 | Yes | 123 2 | No | 123 3 | No | 123 4 | Yes | 123 5 | Yes | 123 1 | No | 124 2 | Yes | 124 3 | No | 124 4 | No | 124 5 | No

Transposing one column in python pandas with the simplest index possible

孤者浪人 提交于 2019-12-23 02:57:17
问题 I have the following data ( data_current ): import pandas as pd import numpy as np data_current=pd.DataFrame({'medicine':['green tea','fried tomatoes','meditation','meditation'],'disease':['acne','hypertension', 'cancer','lupus']}) data_current What I would like to do is to transpose one of the columns, so that instead of having multiple rows with same medicine and different diseases I have one row for each medicine with several columns for diseases. It is also important to keep index as

Transpose rows column in GetRows

流过昼夜 提交于 2019-12-23 02:57:05
问题 Below VBA code does the job, but I'm losing some 3 sec in the transpose part. Is there a way I can get the same result or in the SQL query or in the getrows process without losing the 3 secs? Sub LoadData() Dim strCon, srtQry As String, tmpArray, tmpArray2, R As Variant, i, j As Long Set cn = CreateObject("ADODB.Connection") Set rs = CreateObject("ADODB.Recordset") strCon = "DRIVER={MySQL ODBC 5.2 ANSI Driver};" & _ "SERVER=localhost;" & _ "DATABASE=tbname;" & _ "USER=root;" & _ "PASSWORD

Pandas dataframe transpose with original row and column values

[亡魂溺海] 提交于 2019-12-23 01:52:26
问题 Does anyone know how to transpose pandas dataframe with original row and column values? I am looping through each row and column using .iterrows() but I am sure there is a better way to do this. Maybe using pivot? Thanks! DF looks like a b c 0 11 12 13 1 21 22 23 2 31 32 33 I want the new DF to be row col Val 0 0 a 11 1 0 b 12 2 0 c 13 3 1 a 21 4 1 b 22 5 1 c 23 6 2 a 31 7 2 b 32 8 2 c 33 回答1: Here is one way using stack() . res = df.stack().reset_index() res.columns = 'row col Val'.split()

How to use Pivot in SQL Server

假如想象 提交于 2019-12-23 01:45:11
问题 I have table like this ID TimeStamp Statement Action 8082837636688904709 2012-07-23 16:03:25.000 UPDATE Skill name="French" SET state="1" 1 8082837636688904709 2012-07-23 16:03:25.000 UPDATE Skill name="French" SET state="2" 2 and I want to transpose it like: ID TimeStamp UndoStatement RedoStatement 8082837636688904709 2012-07-23 16:03:25.000 UPDATE Skill name="French" SET state="1" UPDATE Skill name="French" SET state="2" This is my query: SELECT ID, Timestamp, [UndoStatement],

How to transpose lines to column for only 7 rows at a time in file

浪尽此生 提交于 2019-12-22 18:19:28
问题 Please help, I have a text file that looks something like this: ID: 000001 Name: John Smith Email: jsmith@ibm.com Company: IBM blah1: a blah2: b blah3: c ID: 000002 Name: Jane Doe Email: jdoe@ibm.com Company: IBM blah1: a blah2: b blah3: c ID:000003 . . . etc. Notice that each customer's info is in 7 rows. The ID:000002 marks the start of the next customer, 000003 the next customer, so on and so forth. I would like my output file to be like this (instead of each customer's data in the next