transpose
SQL Server 2008 Vertical data to Horizontal
You can use the PIVOT function to convert your rows of data into columns. Your original query can be used to retrieve all the data, the only change I would make to it would be to exclude the column b.field_id because this will alter the final display of the result. If you have a known … Read more
Multi-dimensional array transposing
I saw that all of the answers create a new resultant matrix. This is simple: matrix[i][j] = matrix[j][i]; However, you can also do this in-place, in case of square matrix. // Transpose, where m == n for (int i = 0; i < m; i++) { for (int j = i + 1; j < … Read more
Repeat each row N times in Google Sheets
Without splitting and joining and other string manipulations, =ARRAYFORMULA(FLATTEN(IF(SEQUENCE(ROWS(A2:A4),5),A2:A4))) A2:A4 The range to repeat 5 Number of times to repeat SEQUENCE to create a 2D array of numbers IF to transpose a 1D array A2:A4 to a 2D array of size equal to the SEQUENCE array created FLATTEN the 2D to 1D array. A1 Name … Read more
Convert column to row in Python Pandas
You need set_index with transpose by T: print (df.set_index(‘fruits’).T) fruits apples grapes figs numFruits 10 20 15 If need rename columns, it is a bit complicated: print (df.rename(columns={‘numFruits’:’Market 1 Order’}) .set_index(‘fruits’) .rename_axis(None).T) apples grapes figs Market 1 Order 10 20 15 Another faster solution is use numpy.ndarray.reshape: print (pd.DataFrame(df.numFruits.values.reshape(1,-1), index=[‘Market 1 Order’], columns=df.fruits.values)) apples grapes … Read more
Transpose and flatten two-dimensional indexed array where rows may not be of equal length
$data = array( 0 => array( 0 => ‘1’, 1 => ‘a’, 2 => ‘3’, 3 => ‘c’, ), 1 => array( 0 => ‘2’, 1 => ‘b’, ), ); $newArray = array(); $mi = new MultipleIterator(MultipleIterator::MIT_NEED_ANY); $mi->attachIterator(new ArrayIterator($data[0])); $mi->attachIterator(new ArrayIterator($data[1])); foreach($mi as $details) { $newArray = array_merge( $newArray, array_filter($details) ); } var_dump($newArray);
Excel: Formulas for converting data among column / row / matrix
The idea is to give here something that can likely be used with minor adaptations to the questions listed above, which may also serve as a reference for future related questions. The essential functions to be used are INDEX or OFFSET. The pros and cons of each one will be given after explicit examples, with … Read more
Aggregate, Collate and Transpose rows into columns
You cannot concatenate a range of cells (aka Letters) using native worksheet functions without knowing the scope beforehand. As your collection of strings into groups has random numbers of elements, a VBA loop approach seems the best (if not the only) way to address the issue. The loop can make determinations along the way that … Read more
How to transpose a dataset in a csv file?
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, 5, 6), (7, 8, 9)] zip(*a) # [(1, 4, 7), # (2, 5, 8), # … Read more