Matrix and match - excel

I have a dataset in excel, like this and I need to do a match for doing the matrix but I don't know how to do, I can't order (my real dataset it's more complicated than this)
I would like to have an array that multiplies data that are similar to each other. In this case A = A and aa = aa as a condition to then make the final matrix, ideas?
I have used match but it does not execute the function correctly

Try using SUMPRODUCT() Function --> Simply multiplies arrays together and returns the sum of products.
• Formula used in cell K2
=SUM(($A2=$G$2:$G$5)*($B2=$H$2:$H$5)*(C2*$I$2:$I$5))
And Fill Down & Fill Right !!!

Try this:
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
Condition 1
Condition 2
Condition 1 & Condition 2
Machine 1
Machine 2
Machine 3
Index 1
Index 2
Index 1 & Index 2
Timeprod
Machine 1
Machine 2
Machine 3
A
aa
=A2&B2
0,2
1
0
B
aa
=H2&I2
0,5
=VLOOKUP($C2,$J:$K,2,FALSE)*D2
=VLOOKUP($C2,$J:$K,2,FALSE)*E2
=VLOOKUP($C2,$J:$K,2,FALSE)*F2
B
aa
=A3&B3
1
2
0
D
bb
=H3&I3
1
=VLOOKUP($C3,$J:$K,2,FALSE)*D3
=VLOOKUP($C3,$J:$K,2,FALSE)*E3
=VLOOKUP($C3,$J:$K,2,FALSE)*F3
C
bb
=A4&B4
0
0
0
C
bb
=H4&I4
2
=VLOOKUP($C4,$J:$K,2,FALSE)*D4
=VLOOKUP($C4,$J:$K,2,FALSE)*E4
=VLOOKUP($C4,$J:$K,2,FALSE)*F4
D
bb
=A5&B5
0
0
6
A
aa
=H5&I5
0,2
=VLOOKUP($C5,$J:$K,2,FALSE)*D5
=VLOOKUP($C5,$J:$K,2,FALSE)*E5
=VLOOKUP($C5,$J:$K,2,FALSE)*F5

Related

Median with various criteria

here's my problem: I need to calculate the median from the following table:
V1 V2 Total
A 0 0
B 2 10
C 2 12
D 2 19
E 2 22
A 2 4
B 1 12
D 1 0
C 2 8
A 0 10
D 1 15
A 2 12
B 2 10
E 1 16
Criteria are as follows:
'B', 'C', and 'D' from column V1
not zero from column Total
calculate median from column Total
Until now, the formula works perfectly:
=MEDIAN(IF(B2:B15={"B","C","D"},IF(NOT(D2:D15="0"),D2:D15)))
And now comes the hard part. It has to include another criteria, which is:
'A' from column V1 only if not 0 in column V2
I have no idea how to embed it in the code above, because it gives me various types of errors, depending on what I try.
An idea using Microsoft365:
Formula in E2:
=MEDIAN(FILTER(C2:C15,(ISNUMBER(FIND(A2:A15,"BCD")))*(C2:C15<>0)+(A2:A15="A")*(B2:B15<>0)))

How can I duplicate a row and append it directly after the duplicated row using pandas?

I've been trying to figure this problem for a couple of hours now and seem to reach a dead end everytime. A small example of what I want to do is shown below.
Normal Series
a
b
c
d
Duplicated Series
a
a
b
b
c
c
d
d
Try with loc and df.index.repeat:
>>> df.loc[df.index.repeat(2)]
Normal Series
0 a
0 a
1 b
1 b
2 c
2 c
3 d
3 d
>>>
Or with reset_index:
>>> df.loc[df.index.repeat(2)].reset_index(drop=True)
Normal Series
0 a
1 a
2 b
3 b
4 c
5 c
6 d
7 d
>>>
You can just concat a duplicated series together and sort it.
sample = pd.Series(['a','b','c','d'])
output = pd.concat([sample,sample]).sort_values().reset_index(drop=True)
output

SUM based on list of categories

Consider the following Excel
A B C D
1 foo 7 whaa
2 bar 5 AA
3 baz 9 BB
4 bal 1 AA
5 oof 3 blah
6 aba 9 C
Extra:
Each row has either a value in column C OR in column D
The values in column Care categories (in this example ÀA,BB,C`)
The values in column Dcan be anything
I need a SUM (based on column A) as follows:
SUM of column B for all lines that have a value in (any value) in column D (called Rest)
SUM of column B for each category in column C. I have a list of the categories (see below)
So like this:
A B
1 Rest 10 <----- 7 + 3
2 AA 6 <----- 5 + 1
3 BB 9
4 C 9
What formulas do I need in column B above to get this result?
or, you can use sumproduct to solve:
H2=SUMPRODUCT(($D$4:$D$9=IF(G2="Rest","",G2))*$C$4:$C$9)
H2=SUMIF($D$4:$D$9,IF(G2="Rest","",G2),$C$4:$C$9)

Python Pandas: copy several columns at specific row from one dataframe to another with different names

I have dataframe1 with columns a,b,c,d with 5 rows.
I also have another dataframe2 with columns e,f,g,h
Let's say I want to copy columns a,b in row 3 from dataframe1 to columns f,g in row 3 at dataframe2.
I tried to use this code:
dataframe2.loc[3,['f','g']] = dataframe1.loc[3,['a','b']].
The results was NaN in dataframe2.
Any ideas how can I solve it?
One idea is convert to numpy array for avoid alignment data by columns names:
dataframe2.loc[3,['f','g']] = dataframe1.loc[3,['a','b']].values
Sample:
dataframe1 = pd.DataFrame({'a':list('abcdef'),
'b':[4,5,4,5,5,4],
'c':[7,8,9,4,2,3]})
print (dataframe1)
a b c
0 a 4 7
1 b 5 8
2 c 4 9
3 d 5 4
4 e 5 2
5 f 4 3
dataframe2 = pd.DataFrame({'f':list('HIJK'),
'g':[0,0,7,1],
'h':[0,1,0,1]})
print (dataframe2)
f g h
0 H 0 0
1 I 0 1
2 J 7 0
3 K 1 1
dataframe2.loc[3,['f','g']] = dataframe1.loc[3,['a','b']].values
print (dataframe2)
f g h
0 H 0 0
1 I 0 1
2 J 7 0
3 d 5 1

Transpose data in Excel

My table currently looks like this:
1 a b c d e
2 a
3 b d g h
4 a c
5 d e j
My desired format is this:
1 a
1 b
1 c
1 d
1 e
2 a
3 b
3 d
3 g
3 h
4 a
4 c
5 d
5 e
5 j
Is there a way to make this modification in Microsoft Excel? I have attempted this in Ms Access but there is a column limit (225) which I exceed. In addition, I have attempted to use the TRANSPOSE function in Excel, but this only switches rows to columns. Please provide suggestions on how this transformation might be achieved. Thanks!

Resources