transpose

Transpose a datatable

跟風遠走 提交于 2019-11-28 12:11:39
问题 I have the data table below. I would like to change the data table to transform the data table into the one next to it. How can I do this? The reason why i would like o do this is because the excel file brings the data in like shown and then i would like to sort this data out on Row 1 Current table || Col 1 || Col 2 || Col 3 ____________________________________ Row 1 || 10 || 20 || 30 Row 2 || 1 || 2 || 3 New Datatable || Row 1 || Row 2 Col 1 || 10 || 1 Col 2 || 20 || 2 Col 3 || 30 || 3 回答1:

Numpy transpose functions speed and use cases

浪子不回头ぞ 提交于 2019-11-28 12:06:57
问题 So why is the NumPy transpose .T faster than np.transpose() ? b = np.arange(10) #Transpose .T t=b.reshape(2,5).T #Transpose function t = np.transpose(b.reshape(2,5)) #Transpose function without wrapper t = b.reshape(2,5).transpose() I did a timeit of both in Jupyter: %timeit -n 1000 b.reshape(2,5).T 1000 loops, best of 3: 391 ns per loop %timeit -n 1000 np.transpose(b.reshape(2,5)) 1000 loops, best of 3: 600 ns per loop %timeit -n 1000 b.reshape(2,5).transpose() 1000 loops, best of 3: 422 ns

Swap 2D array's rows and columns

你离开我真会死。 提交于 2019-11-28 11:32:36
问题 I need to get columns from a CSV file into an array (multidimensional array or array of arrays). I used CSV.au3 which loads the rows just fine, but I need the columns in that place. My CSV file looks like: Item 1, Item 2, Another Item Item 3, Item 4 It creates a multidimensional array that looks like: $aResult[0] = [0] => 'Item 1', [1] => 'Item 2', [2] => 'Another Item' $aResult[1] = [0] => 'Item 3', [1] => 'Item 4' Where I would like it to look like: $aResult[0] = [0] => 'Item 1', [1] =>

Transpose a matrix in racket (list of lists

半城伤御伤魂 提交于 2019-11-28 11:31:24
I got a list of lists in racket and have to transpose them. (: transpose ((list-of(list-of %a)) -> (list-of (list-of %a)))) (check-expect (transpose (list (list 1 2 3) (list 4 5 6))) (list (list 1 4) (list 2 5) (list 3 6))) (define transpose (lambda (xs) (cond ((empty? xs)empty) ((pair? xs)(make-pair (make-pair (first(first xs)) (make-pair (first(first(rest xs)))empty)) (transpose (rest(rest xs)))))))) That's my code at the moment. I think the problem is in the recursive call (correct me if I'm wrong please). The actual outcome is (list (list 1 4)) . The rest seems kinda ignored. It would

Transpose array and actually reorder memory

早过忘川 提交于 2019-11-28 10:58:19
I have a 3-D NumPy array, e.g. a = np.random.random((2,3,5)) I would like to transpose the last two axes, i.e. b = a.transpose(0,2,1) However, I do not want a view with twiddled strides! I want to actually copy the array and reorder it in memory . What is the best way to achieve this? The copy() method will reorder to C-contiguous order by default: b = a.transpose(0,2,1).copy() 来源: https://stackoverflow.com/questions/19826262/transpose-array-and-actually-reorder-memory

SQL to transpose row pairs to columns in MS ACCESS database

ε祈祈猫儿з 提交于 2019-11-28 10:20:11
I have an MS Access database that contains translated sentences in source-target pairs (a translation memory for fellow users of CAT tools). Somewhat annoyingly, source and target are not stored in separate columns, but in rows linked by ID, like this: +---+----+--------------+ |id |lang| text | +---+----+--------------+ 1 a lang a text 1 b lang b text 2 a more a text... 2 b more b text... +---+----+--------------+ What SQL could I use to turn that into a table such as: +---+--------------+--------------+ |id | lang A | lang B | +---+--------------+--------------+ 1 lang a text lang b text 2

Searching for unique values in dataframe and creating a table with them

落花浮王杯 提交于 2019-11-28 09:11:14
问题 Since I started using R< not long ago, I've found this site very useful in helping me build my scripts. I have yet again came across a challenge for which I can't seem to find an answer anywhere. Here is my problem: In my data I have a column which contains a different URL in each row. In each of those URL's there is a particular piece of information I want to extract. Currently I do it in excel because I've been told it's impossible to do in R and that no function exists to do it. The URL

How can I turn part of the Excel data to columns to get a desired output?

痴心易碎 提交于 2019-11-28 02:16:38
For eg - Say I have data in the following format - Current Format I would need the data to be formatted in the following format for ease of use - Required Format Of course the data contains a lot more records - I'm looking for an easy way to transpose data in this way for large sets of data. Any help will be appreciated :) This is very easy with PowerQuery. It is inbuilt for Excel 2016 and a freely available add in for Version from 2010 to 2013. You would set your data up as a table excluding the first row which contains the text Number of Cases (Ctrl + T whilst bring up window to create table

Results transposed with R apply [duplicate]

泪湿孤枕 提交于 2019-11-28 02:09:55
This question already has an answer here: Why apply() returns a transposed xts matrix? 1 answer Apologies, I just realised that this has already been answered here . This should be pretty basic but I do not really understand why it is happening. Can someone help? This is the simple code with the example 'data': applyDirichletPrior <- function (row_vector) { row_vector_added <- row_vector + min (row_vector) row_vector_result <- row_vector_added / sum(row_vector_added) } data <- matrix(c(1,2,3,4,5,6,7,8), nrow=2, ncol=4) applied <- apply(data, 1, function(x) applyDirichletPrior(x)) The output is

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

旧城冷巷雨未停 提交于 2019-11-28 01:36:29
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_price', values='last_traded_price') Pivot isn't working due to duplicate rows in selection_id. is it possible