Questions tagged [reshape]

In R, Matlab, NumPy and APL, reshape functions allow data to be transformed into more convenient forms.

Reshape functions allow data to be transformed into more convenient forms.

R

The function reshapes a data frame between ‘wide’ format with repeated measurements in separate columns of the same record and ‘long’ format with the repeated measurements in separate records.

Matlab

The function allows a vector or array to be transformed into a new array with the specified dimensions.
Note that reshape does not change the order of the elements or the number of elements in the array. reshape only affects its shape.

NumPy

The function gives a new shape to an array without changing its data. The returned array will be a new view object if possible; otherwise, it will be a copy.

APL

The function allows any array to be transformed into a new array with the specified shape. Note that does not change the order of the elements, however it can change the number of elements in the array, recycling elements if they are insufficient to fill the requested shape, or truncating trailing elements if the requested shape cannot hold them all.

3858 questions
1
vote
1 answer

Reshaping the current dataframe into another dataframe and creating new columns (concatenate)

I have the attached dataframe (here) and I need to reshape it to be in the format shown below Basically, I want to add each compare each traet group (LA, RA, BiA) to NP treat group and create a column that is concatenate between Studlab and treat…
Mohamed Rahouma
  • 1,084
  • 9
  • 20
1
vote
1 answer

Issues reshaping data.frame from wide to long format

I'm trying to reshape the below data frame into a long format, but I'm not having much luck writing the code using reshape() or melt(). pH SO4 Lake Lat Long 1976 1977 1978 1981 1976 1977 1 …
Sarah
  • 13
  • 3
1
vote
2 answers

Alternatives to using numpy reshape((-1,1))

I find myself reshaping 1D vectors way to many times. I wonder if this is because I'm doing something wrong, or because it is an inherit fault of numpy. Why can't numpy infer that when he gets an object of shape (400,) to transform it to (400,1) ?…
Maverick Meerkat
  • 5,737
  • 3
  • 47
  • 66
1
vote
1 answer

Going from panel format to wide format and back in R data.table: How to preserve variable names?

I have a panel data set with a large number of time periods and units, and also a large number of variables which I observe for each period and unit. Since I want to apply a univariate time series operation for each unit and variable, I have to…
Florestan
  • 127
  • 1
  • 15
1
vote
1 answer

How to insert an array into existing multi-dimensional array by index? [Python]

I manipulated the MNIST dataset for research, by adding a set of digits to each digit in the dataset. Before manipulation: In: x_train.shape Out: (60000, 28, 28) Expectated result after manipulation: In: x_train_new.shape Out: (60000, 11, 28,…
Audiogott
  • 95
  • 2
  • 12
1
vote
1 answer

Reshaping Data in R with Reshape

I have this dataset and for the life of me, I couldn't figure out how to get it in the format I want. I know that I needed to use melt from reshape package and possibly do a bit of transpose... Would appreciate any help! Thank you! Reproducible…
Javier
  • 730
  • 4
  • 17
1
vote
3 answers

Pandas reshape a multicolumn dataframe long to wide with conditional check

I have a pandas data frame as follows: id group type action cost 101 A 1 10 101 A 1 repair 3 102 B 1 5 102 B 1 repair 7 102 B 1 …
lucatrv
  • 725
  • 8
  • 14
1
vote
2 answers

Reshaping wide to tall data over multiple variables

Currently my data looks like this: wide.df <- read.table(header = T, sep = ",", text = " ID, left.mid.brain, right.mid.brain, left.lat.brain, right.lat.brain, score, group 100, 18 , 4, 29, 30, 40, 0 101, 19, 7, 33, 40, 29, 0 103, 19, 19, 22, 30,…
crich
  • 99
  • 3
  • 8
1
vote
1 answer

Why to reshape MSER contours before detecting texts?

I am using MSER from opencv-python to detect text using the code from this stackoverflow question. Can anyone help me understand why the contour p is being reshaped to (-1, 1, 2) before computing the convex hull of the objects? The code is as…
Shreyas Moolya
  • 339
  • 4
  • 19
1
vote
1 answer

Reshaping layer in Keras

I am trying to build a convolutional neural network with an output matrix. The input shape is (100,100,4) and the output shape is (2,125). Here is the summary of my current…
anoa
  • 13
  • 3
1
vote
1 answer

Reshape wide error as timevar is not separated

I have a long dataset like this: Currency Year Percentage 1 PEN 2009 0.630 2 PEN 2010 0.584 3 PEN 2011 0.618 4 PEN 2012 1.03 5 PEN 2013 1.00 6 PEN 2014 …
Rainroad
  • 191
  • 8
1
vote
0 answers

How to use spread function to get an equivalent result to cast()

I have been informed that the reshape package has not been actively maintained for a long long while; also, i have noticed that the number coming out from the cast() function is not accurate in my case, so now I am looking into the spread() function…
mmkuchi
  • 11
  • 3
1
vote
1 answer

From long to wide format, where new generated columns flexibly reflect order of value occurrence

I'm trying to reformat my dataset from long to wide format, but while this is one of the most discussed topics, I couldn't find a solution for my case, nor to generalize from methods others have used. My data is in long format, where each ID has a…
Emman
  • 3,695
  • 2
  • 20
  • 44
1
vote
1 answer

Combine repeated columns in the same Dataframe

I have data from various csv files I am trying to put together. I put it all in one Dataframe. How can I combine the data into the corresponding A, B, C columns and include a header for each row? for data_base in data: …
Nycbros
  • 95
  • 8
1
vote
2 answers

pandas reshape multi key value dataframe colums to rows

I have a dataframe like: How can it be reshaped that the columns (0 => 1, 2=> 3) are stored as records? I.e. columns metric_name and metric_value and multiple rows (observations)? pandas_dict = {0: {0: 'Model:', 1: 'Dependent Variable:', 2:…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292