How can I transform rows to columns?
I have this table with data below and need help because I don't know which formula can I use to convert the table into the desired one.
I don't know if it's possible with ARRAYFORMULA
, QUERY
or TRANSPOSE
Current Data Set:
Date | E1 | E2 | E3 |
---|---|---|---|
4/01/2021 | 4,17% | 3,53% | 3,16% |
11/01/2021 | 4,40% | 3,69% | 3,58% |
18/01/2021 | 4,93% | 4,39% | 4,10% |
Expected Output:
Date | Type | Metric |
---|---|---|
4/01/2021 | E1 | 4,17% |
4/01/2021 | E2 | 3,53% |
4/01/2021 | E3 | 3,16% |
11/01/2021 | E1 | 4,40% |
11/01/2021 | E2 | 3,69% |
11/01/2021 | E3 | 3,58% |
18/01/2021 | E1 | 4,93% |
18/01/2021 | E2 | 4,39% |
18/01/2021 | E3 | 4,10% |
1 answer
-
answered 2022-05-06 20:54
player0
use:
={"Date"\ "Type"\ "Metric"; INDEX(QUERY(SPLIT( FLATTEN(A2:A6&"×"&B1:L1&"×"&B2:L6); "×"); "where Col3 is not null"; ))}
do you know?
how many words do you know
See also questions close to this topic
-
How to get pass an array through a function with a user input?
I want to ask the user for the size of a 2D array arr[][], but also pass it through the function initializeArray. However, if I pass it through the function, I would have to have a size declarator for col, which doesn't allow the user to enter their own value for the size
#include<iostream> using namespace std; void initializeArray(arr[][10], int N); int main() { int N; cout << "enter an array size: "; cin >> N; int arr[N][N]; initializeArray(arr, N); // I get an error here for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) cout << arr[i][j] << " "; cout << endl; } } void initializeArray(int arr[][10], int N) { for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) arr[i][j] = 0; }
The only solution I found was the make arr[][] a global array, but in that case, I would have to still declare the size parameters, and I want the user to enter whatever they want. Is there another way to fix this?
-
Two-dimensional array C++
Problem: Write a program of a two dimensional integer array of exactly four rows and four columns, and find the sum of the integers each row of the array as well as determine the smallest inputted element/data in the array. The user will input the elements. Display the elements in tabular form. Make the program user friendly. Use a Class and a member function for the process involve.
-
Pass Associative Array from Symfony Controller to Twig and JavaScript
So, I have 2 arrays that I've combined into one array after making sure they're the same length as such.
//Fetching Ratings for All Coaches & Making a Key, Value Associative Array with Coach id as Key and Rating as Value $coaches = $coachRepository->findAll(); $rating = $coachRepository->findRatingByCoach(); //Array of coach IDs $id_array = array(); foreach ($coaches as $c){ $id_array[] = $c->getId(); } $combined = array_combine($id_array, $rating);
Now I want to pass this key, value array to Twig template and JavaScript. I'm currently doing this
return $this->render('...', [ ..., 'combined'=>$combined ]);
And I'm accessing the array in Twig as such
{% for key, value in combined %} {{ key }} - {{ value }} {% endfor %}
And I'm getting this error.
Object of class App\Entity\Coach could not be converted to string
Looking at the Stack Trace I can see that the array combined is being passed in this form.
'combined' => array(object(Coach))
After a bit of debugging it turns out that I thought the issue was with the $
id_array
when in fact it's the $rating
variable that's presenting an issue. I'm not sure why but I'm getting a single float value. I fixed the issue by changing how I'm fetching the $rating, now instead of using a QueryBuilder to get it from the DB, I'm getting it from list of Coaches as such//Array of coach IDs and array of Ratings $id_array = array(); $rating_array = array(); foreach ($coaches as $c){ $id_array[] = $c->getId(); $rating_array [] = $c->getRating(); }
Even if I set the array
-
PERCENTILE IF using ARRAYFORMULA for a set of conditions
I need to calculate the percentile using an if condition to calculate it by group of conditions, but Google Sheets doesn't provide PERCENTILEIF function. A nonarray solution is possible:
=ARRAYFORMULA(PERCENTILE(if(range=value,values),percentile))
but in my case
value
should be an array of possible values.Here is the sample data with the expected result highlighted:
I tried several options to use an array of possible values, but in all cases, I get the wrong result:
Using
JOIN
inG2
:=arrayformula(if(len(E2:E3),percentile(split(regexreplace(join(",", Arrayformula(A2:A12 & "_" & B2:B12)),E2:E3 & "_(\d+)|.",",$1"),","),D2),))
Using
MATCH
inH2
:=ARRAYFORMULA(if(len(E2:E3), PERCENTILE(IFNA(--(match(A2:A12,E2:E3,0) > 0) * B2:B12,),D2),))
here is the Spreadsheet file: https://docs.google.com/spreadsheets/d/1VDJIYvmOC46DI_9u4zSEfmxSan5R5VKK772C_kP5rxA/edit?usp=sharing
-
How do I show Popup Message everytime I go to another Sheet using Google Sheet/Apps Script?
I have 3 sheets in a workbook - Sheet1, Sheet2, and Sheet3, every time I change to a Sheet there is a Popup message that will show up.
What I had in mind...
function onOpen() { var ui = SpreadsheetApp.getUi(); ui.alert('This is my pop up message!'); }
-
Move row to a different sheet when box is checked
Hi I'm very new to coding with Google Sheets and Excel. My goal is to move a row when it is checked off.
The original sheet is called "School Assignments" and the sheet I want to move it to is called "Finished". When a box in column H (column 8) is checked the data value of the row becomes "Done". When it is not marked it is "Unfinished".
I want the row to move to the Finished sheet when I mark it as "Done". I also want this to work vice versa where when I uncheck and it becomes "Unfinished" it it goes back to the School Assignments sheet. I have some code but honestly it was done months ago (I'm coming back to this project after a break) and I'm not sure what I was thinking when I wrote it or if it is correct at all. It doesn't work obviously.
if(sh.getName() == "School Assignments" && e.range.columnStart == 8 && e.value == "Done") { let tsh = e.source.getSheetByName("Finished"); sh.getRange(e.range.rowStart, 1, 1, sh.getLastColumn()).moveTo(tsh.getRange(tsh.getLastRow() + 1, 1)); sh.deleteRow(e.range.rowStart); } else if(sh.getName() == "Finished" && e.range.columnStart == 8 && e.value == "Unfinished") { let tsh = e.source.getSheetByName("School Assignments"); let trg = tsh.getRange(tsh.getLastRow() + 1, 1); sh.getRange(e.range.rowStart, 1, 1, sh.getLastColumn()).moveTo(trg); sh.deleteRow(e.range.rowStart); } }
I also have an auto-sorting piece earlier in the code which defines some constants.
const ss = SpreadsheetApp.getActiveSpreadsheet() const ws = ss.getSheetByName("School Assignments") const range = ws.getRange(2,1,ws.getLastRow()-1,8) range.sort({column: 7, ascending: true }) }
I am totally unsure how to fix this and accomplish what I'm looking to do.
-
Reverse words in a string in C++
Can anyone please tell that why the below written code isnt working , theres no error but its simply printing the string which was passed and is not reversing it.
Logic: First reverse individual words and after reversing all the words in a string simply reverse the entire string.
I/P : hello world O/P : world hello
Below is the code:
#include <bits/stdc++.h> using namespace std; void reverse(string str,int low, int high){ while(low<=high){ swap(str[low],str[high]); low++; high--; } } void reverseWords(string str){ int start=0; int n = str.length(); for(int end=0;end<n;end++){ if(str[end]==' '){ reverse(str,start,end-1); start=end+1; } } reverse(str,start,n-1); reverse(str,0,n-1); cout<<str; } int main() { string s = "Welcome to Gfg"; cout<<"After reversing words in the string:"<<endl; reverseWords(s); return 0; }
-
creating a list from a column with multiple lines
I have a Pandas data frame that in one column called SourceDocument I have multiple lines of data in each cell (separated by \n).
SourceDocuments
PRDS-002039\nPRDS-001952\nPRDS-001956
I would like to run a for loop that reads each row and then separates these lines into a list. Eventually, I wanna have a dictionary where the value is the list of split items. for example:
SourceID
546785: ['PRDS-002039','PRDS-001952','PRDS-001956']
The dict keys(546785) are generated through another for loop I wrote the below code but can't figure out how to do the split row-by-row
valuez=[] for j in range (0,ABP215.shape[0]): valuez.append(ABP215['SourceDocuments'][j].split('\n'))
APB215 is the Pandaas dataframe name.
I get this error:
AttributeError: 'float' object has no attribute 'split'
any help would be appreciated.
-
Summarize and transpose selected columns
df1 Reg Source Year Values A From1 2003 7512 B From1 2000 7830 C From1 2000 7830 C From2 2001 7830 D From1 2002 1734 D From2 2003 1734
I have a dataframe (df1) that I group_by Reg, Source and Year, then transpose the columns Year into rows names, and Values into rows, but I keep Reg and Source as columns. Expected result is:
Output Reg Source 2000 2001 2002 2003 A From1 0 0 0 7512 B From1 7830 0 0 0 C From1 7830 0 0 0 C From2 0 7830 0 0 D From1 0 0 1734 0 D From2 0 0 0 1734
I might have duplicates values so when I group_by(Reg, Source, Year) then spread() it returns an error
Each row of output must be identified by a unique combination of keys
-
pandas df elements from list into column
I have this DF:
Elemento_lista DISPLAYNAME Rdo_Encontrado 0 90S VALASION [('90S VALASION', 100, 0), ('90S VALASION', 100, 1), ('90S VALASION', 100, 2), ('90S VALASION', 100, 3)] 1 ADIZERO RC 2 W [('ADIZERO RC 2 W', 100, 11), ('ADIZERO RC 2 W', 100, 12), ('ADIZERO RC 2 W', 100, 13), ('ADIZERO RC 2 W', 100, 14)] 2 ASWEERUN [('ASWEERUN', 100, 16), ('ASWEERUN', 100, 17), ('90S VALASION', 34, 0), ('90S VALASION', 34, 1)] As it can bee seen, Rdo_Encontrado Column´s value is a List. I need a new row, for each element, and 3 new columns, with values from each list element. The Output should look like this:
Elemento_lista DISPLAYNAME Coincidencia Score idx 0 90S VALASION 90S VALASION 100 0 0 90S VALASION 90S VALASION 100 1 0 90S VALASION 90S VALASION 100 2 0 90S VALASION 90S VALASION 100 3 1 ADIZERO RC 2 W ADIZERO RC 2 W 100 11 1 ADIZERO RC 2 W ADIZERO RC 2 W 100 12 1 ADIZERO RC 2 W ADIZERO RC 2 W 100 13 1 ADIZERO RC 2 W ADIZERO RC 2 W 100 14 2 ASWEERUN ASWEERUN 100 16 2 ASWEERUN ASWEERUN 100 17 2 ASWEERUN ASWEERUN 34 0 2 ASWEERUN ASWEERUN 34 1 Is it possible to do something like this?. I couldn´t find a way...
-
GSheets Forumula Stalls on Tie Score Number
Background Information
I am trying to setup a 1st, 2nd and 3rd rank/scoring system on Google Sheets. The sheet is setup by row and once a week a new row is added.
1. On the left-hand side of each row there are six columns. The top of each column is a cell that contains the value identifier for that column (such as a person's name or ID#). Each week the score is entered into each column.
2. The right-hand side of each row is to identify the 1st, 2nd and 3rd place winners. This area also contains six columns with the headers 1st, 2nd, 3rd. I'm trying to set it up so that each week when the new numbers are added to the next row, the relevant score is shown and the cell next to it shows the name/ID associated with that week's score. Then repeat for 2nd and 3rd.
Problem
Everything works perfectly; unless there is a tie. In that situation the information is duplicated because it stalls on the first match. I have attempted various things, including using "RANK()" and a helper column to eliminate duplicate scores, but as of yet this has me stumped. How can this be solved?
To illustrate what I am trying to do, I have an editable example sheet here: https://docs.google.com/spreadsheets/d/1bmt77kQOtCu8OybNrWH48XKjBKD_HEZ_B6TqweZKEAI/edit?usp=sharing
-
Define flatten layer in neural network using pytorch
I'm trying to define a flatten layer before initiating fully connected layer. As my input is a tensor with shape
(512, 2, 2)
, so I want to flatten this tensor before FC layers.I used to get this error:
empty(): argument 'size' must be tuple of ints, but found element of type Flatten at pos 2
import torch.nn as nn class Network(nn.Module): def __init__(self): super(Network,self).__init__() self.flatten=nn.Flatten() self.fc1=nn.Linear(self.flatten,512) self.fc2=nn.Linear(512,256) self.fc3=nn.Linear(256,3) def forward(self,x): x=self.flatten(x) # Flatten layer x=torch.ReLU(self.fc1(x)) x=torch.ReLU(self.fc2(x)) x=torch.softmax(self.fc3(x)) return x