transpose

How to transpose a dataset in a csv file?

試著忘記壹切 提交于 2019-11-26 10:59:06
问题 For example, i would like to transform: Name,Time,Score Dan,68,20 Suse,42,40 Tracy,50,38 Into: Name,Dan,Suse,Tracy Time,68,42,50 Score,20,40,38 EDIT: the original question used the term \"transpose\" incorrectly. 回答1: If the whole file contents fits into memory, you can use import csv from itertools import izip a = izip(*csv.reader(open("input.csv", "rb"))) csv.writer(open("output.csv", "wb")).writerows(a) You can basically think of zip() and izip() as transpose operations: a = [(1, 2, 3), (4

Transposing a column in a pandas dataframe while keeping other column intact with duplicates

和自甴很熟 提交于 2019-11-26 10:02:01
问题 My data frame is as follows selection_id last_traded_price 430494 1.46 430494 1.48 430494 1.56 430494 1.57 430495 2.45 430495 2.67 430495 2.72 430495 2.87 I have lots of rows that contain selection id\'s and I need to keep selection_id column the same but transpose the data in last traded price to look like this. selection_id last_traded_price 430494 1.46 1.48 1.56 1.57 e.t.c 430495 2.45 2.67 2.72 2.87 e.t.c I\'ve tried a to use a pivot (df.pivot(index=\'selection_id\', columns=last_traded

Excel VBA - Range.Copy transpose paste

走远了吗. 提交于 2019-11-26 09:54:13
问题 I\'m trying to something very simple, but I seem to be stuck. I am following the help menu for PasteSpecial but I cannot seem to get my code to work without an error. I want to take Worksheets(\"Sheet1\").Range(\"A1\",\"A5\") and paste transpose to Worksheets(\"Sheet2\").Range(\"A1\",\"E1\") . What is the most simple way to accomplish this? 回答1: Worksheets("Sheet1").Range("A1:A5").Copy Worksheets("Sheet2").Range("A1").PasteSpecial Transpose:=True 来源: https://stackoverflow.com/questions

How does NumPy's transpose() method permute the axes of an array?

别说谁变了你拦得住时间么 提交于 2019-11-26 08:45:46
问题 In [28]: arr = np.arange(16).reshape((2, 2, 4)) In [29]: arr Out[29]: array([[[ 0, 1, 2, 3], [ 4, 5, 6, 7]], [[ 8, 9, 10, 11], [12, 13, 14, 15]]]) In [32]: arr.transpose((1, 0, 2)) Out[32]: array([[[ 0, 1, 2, 3], [ 8, 9, 10, 11]], [[ 4, 5, 6, 7], [12, 13, 14, 15]]]) When we pass a tuple of integers to the transpose() function, what happens? To be specific, this is a 3D array: how does NumPy transform the array when I pass the tuple of axes (1, 0 ,2) ? Can you explain which row or column these

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

老子叫甜甜 提交于 2019-11-26 08:06:33
问题 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

Get the first column of a matrix represented by a vector of vectors

試著忘記壹切 提交于 2019-11-26 07:42:44
问题 Suppose I\'m representing a matrix foo of values using std::vector : int rows = 5; int cols = 10; auto foo = vector<vector<double>>(rows, vector<double>(cols)); Is there a cleverly simple way for me to get a vector<int> of size rows that contains the first \"column\" of foo: {foo[0][0], foo[0][1], foo[0][2], foo[0][3], foo[0][4] } Put another way, can I \"transpose\" foo so that the following three things are true: foo_transpose.size() == cols foo_transpose[0].size() == rows foo_transpose[0]

Postgres - Transpose Rows to Columns

删除回忆录丶 提交于 2019-11-26 06:33:07
问题 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] 回答1: Use crosstab() from the tablefunc module. SELECT * FROM crosstab( $$SELECT user_id, user_name, rn, email_address FROM ( SELECT u

Transposing a NumPy array

跟風遠走 提交于 2019-11-26 03:21:14
问题 I use Python and NumPy and have some problems with \"transpose\": import numpy as np a = np.array([5,4]) print(a) print(a.T) Invoking a.T is not transposing the array. If a is for example [[],[]] then it transposes correctly, but I need the transpose of [...,...,...] . 回答1: It's working exactly as it's supposed to. The transpose of a 1D array is still a 1D array! (If you're used to matlab, it fundamentally doesn't have a concept of a 1D array. Matlab's "1D" arrays are 2D.) If you want to turn

Pivot Dynamic Columns, no Aggregation

岁酱吖の 提交于 2019-11-26 03:15:26
问题 I have questionnaire data in, SQL Server 2008, that I want to transpose to a matrix. I saw several posts about the same topic, but I just don\'t get pivoting. Given are following tables: Question table Answer table Customer table The columns: [CustomerID] , [QuestionName_1] , .., [QuestionName_n] <- dynamic number of question columns) The data: CustomerID , Answer_1 , .., Answer_n The code to retrieve the columns: DECLARE @columns VARCHAR(8000) SELECT @columns = COALESCE(@columns + \',[\' +

Transposing a 2D-array in JavaScript

…衆ロ難τιáo~ 提交于 2019-11-26 03:14:10
问题 I\'ve got an array of arrays, something like: [ [1,2,3], [1,2,3], [1,2,3], ] I would like to transpose it to get the following array: [ [1,1,1], [2,2,2], [3,3,3], ] It\'s not difficult to programmatically do so using loops: function transposeArray(array, arrayLength){ var newArray = []; for(var i = 0; i < array.length; i++){ newArray.push([]); }; for(var i = 0; i < array.length; i++){ for(var j = 0; j < arrayLength; j++){ newArray[j].push(array[i][j]); }; }; return newArray; } This, however,