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);

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