ID Height Phase Corrected_Height Final
1 0 A 0 0
2 1.2 A 1.2 1.2
3 3.9 A 3.9 3.9
4 5.8 A 5.8 5.8
5 4.6 A NA 7.7
6 7.7 A 7.7 9.3
7 9.3 A 9.3 10.8
..
300 237.5 P 237.5 ..
301 234.7 D 234.7 ..
302 233.3 D 233.3 ..
303 235.1 D NA ..
555 1.0 D 1.0
I have a set of data of similar structure. Calculation of the Phase column was done according to the formula =IF(B2=MAX(B:B);"P";IF(ROW(B2)<MATCH(MAX(B:B);B:B;0);"A";"D"))thanks to #Scott Craner for the solution Naming a behavior in Excel
and to calculate the Corrected_Height column I used =IF(C4="A" & B4>B3;B4; IF(C4="D" & B4<B3;B4;"NA"))). However I did not get the required result. The idea is when in "A" phase, should a lower value arise than the previous one it should change to NA and in "D" phase, should a value be higher than the previous one it should again change to NA. Any suggestion what should I change in the formula? And I also want a final column that gives me the values without NA in it. A,P,and D in phase means Ascent,Peak, and Descent.
The & operator cannot be used to logically and together two conditions in an Excel formula. Instead, use the AND() function:
=IF(AND(C4="A", B4>B3), B4, IF(AND(C4="D", B4<B3), B4, "NA"))
Related
I have this df:
d = pd.DataFrame({'Name':['Andres','Lars','Paul','Mike'],
'target':['A','A','B','C'],
'number':[10,12.3,11,6]})
And I want classify each number in a quartile. I am doing this:
(d.groupby(['Name','target','number'])['number']
.quantile([0.25,0.5,0.75,1]).unstack()
.reset_index()
.rename(columns={0.25:"1Q",0.5:"2Q",0.75:"3Q",1:"4Q"})
)
But as you can see, the 4 quartiles are all equal because the code above is calculating per row so if there's one 1 number per row all quartiles are equal.
If a run instead:
d['number'].quantile([0.25,0.5,0.75,1])
Then I have the 4 quartiles I am looking for:
0.25 9.000
0.50 10.500
0.75 11.325
1.00 12.300
What I need as output(showing only first 2 rows)
Name target number 1Q 2Q 3Q 4Q Rank
0 Andres A 10.0 9.0 10.5 11.325 12.30 1
1 Lars A 12.3 9.0 10.5 11.325 12.30 4
you can see all quartiles has the the values considering tall values in the number column. Besides that, now we have a column names Rank that classify the number according to it's quartile. ex. In the first row 10 is within the 1st quartile.
Here's one way that build on the quantiles you've created by making it a DataFrame and joining it to d. Also assigns "Rank" column using rank method:
out = (d.join(d['number'].quantile([0.25,0.5,0.75,1])
.set_axis([f'{i}Q' for i in range(1,5)], axis=0)
.to_frame().T
.pipe(lambda x: x.loc[x.index.repeat(len(d))])
.reset_index(drop=True))
.assign(Rank=d['number'].rank(method='dense')))
Output:
Name target number 1Q 2Q 3Q 4Q Rank
0 Andres A 10.0 9.0 10.5 11.325 12.3 2.0
1 Lars A 12.3 9.0 10.5 11.325 12.3 4.0
2 Paul B 11.0 9.0 10.5 11.325 12.3 3.0
3 Mike C 6.0 9.0 10.5 11.325 12.3 1.0
I have these data
A B C D
1 lvl1 lvl2 lvl3 value
2 1 1.1 1.1.1 3
3 1 1.1 1.1.2 2
4 1 1.2 1.1.3 7
5 2 2.1 2.1.1 2
6 2 2.1 2.1.2 3
and i want the output of the formula to be like this
7 Type LEVEL value
8 1 level1 12
9 1.1 level2 5
10 1.2 level2 7
11 2 level1 5
12 2.1.1 level3 2
I have already implemented this request with sumifs (cause i have more than one criteria in the original case) by putting in "criteria range" nested if
sumifs(D2:D6,IF(B8="level1",A2:A6),IF(B8="level2",B2:B6),IF(B8="level3",C2:C6))))
Is there any other way (perhaps with index & match?) to have the same result?
If your Levels are exactly the same name as your column headers (so lvl1 instead of level1), then you can use this formula in cell C8 and copied down:
=SUMIFS($D$2:$D$6,INDEX($A$2:$C$6,0,MATCH(B8,$A$1:$C$1,0)),A8)
Put these formulas into H2:I2.
="level"&LEN(G2)-LEN(SUBSTITUTE(G2, ".", ""))+1
=SUMIFS(D:D, INDEX(A:C, 0, LEN(G2)-LEN(SUBSTITUTE(G2, ".", ""))+1), G2)
Fill down.
I've been trying for a while to get a lattice-cell-source running with an ordinary cell-source in MCNP. I can get them both working separately but when I try and combine them I get the following fatal error: distribution 1 for cel is the wrong kind
My source code is as follows:
SDEF PAR=SF
CEL=D9 $ Fatal error. distribution 1 for cel is the wrong kind
X D11
Y D12
Z D13
c
DS9 S 4 10
DS11 S 1 14
DS12 S 2 15
DS13 S 3 16
c
c ---- Lattice cell source-----
SI4 L (3<2[-5:5 -5:5 -10:10]<5)
SP4 1 2540r
SI1 -0.12 0.12
SP1 0 1
SI2 -0.12 0.12
SP2 0 1
SI3 -0.12 0.12
SP3 0 1
c
c ---- Separate cell source ---
SI10 L 25
SP10 1
SI14 22.8 27.2
SP14 0 1
SI15 -2.2 2.2
SP15 0 1
SI16 -2.2 2.2
SP16 0 1
Do any of you know how to declare an embedded source along with an ordinary cell source? Image of the lattice and cell source: light blue indicates source material:
Any help much appreciated.
With help from a colleague we have found a solution, included below. It involves including an FCEL dependency on each distribution, as well as calling the cells directly within the CEL distribution without adding another D-card. Then ALL of the cells must be included in the following distributions.
SDEF PAR=SF
CEL=D9
X=FCEL D11
Y=FCEL D12
Z=FCEL D13
c
c
SI9 L (3<2[-5:5 -5:5 -10:10]<5) 25
c Cells 3 and 25 are called (3 is in the lattice notation)
SP9 1 2540r 2079
c assigning importance to each cell: lattice ~55%, PuO ball ~45%
DS11 S 1 2540r 14
c First 2541 cells have D1 attached, the last cell is attached to D14
DS12 S 2 2540r 15
c First 2541 cells have D2 attached, the last cell is attached to D15
DS13 S 3 2540r 16
c First 2541 cells have D3 attached, the last cell is attached to D16
c
c ---- Lattice cell source-----
SI1 -0.12 0.12
SP1 0 1
SI2 -0.12 0.12
SP2 0 1
SI3 -0.12 0.12
SP3 0 1
c
c ---- Separate cell source ---
SI14 22.8 27.2
SP14 0 1
SI15 -2.2 2.2
SP15 0 1
SI16 -2.2 2.2
SP16 0 1
It's always tricky trying to do so without much context.
I am struggling to find the sum of distinct id's value. Example given below.
Week TID Ano Points
1 111 ANo1 1
1 112 ANo1 1
2 221 ANo2 0.25
2 222 ANo2 0.25
2 223 ANo2 0.25
2 331 ANo3 1
2 332 ANo3 1
2 333 ANo3 1
2 999 Ano9 0.25
2 998 Ano9 0.25
3 421 ANo4 0.25
3 422 ANo4 0.25
3 423 ANo4 0.25
3 531 ANo5 0.5
3 532 ANo5 0.5
3 533 ANo5 0.5
From the above data i need to bring the below result. Could anyone help please using some excel formula?
Week Points_Sum
1 1
2 1.50
3 0.75
You say "sum of distinct id's value"? All the IDs are different so I'm assuming you want to sum for each different "Ano" within the week?
=SUM(IF(FREQUENCY(IF(A$2:A$17=F2,MATCH(C$2:C$17,C$2:C$17,0)),ROW(A$2:A$17)-ROW(A$2)+1),D$2:D$17))
confirmed with CTRL+SHIFT+ENTER
where F2 contains a specific week number
Assumes that each "Ano" will always have the same points value
Probably not the most efficient solution... but this array formula works:
= SUMPRODUCT(IF($A$2:$A$15=$F2,$D$2:$D$15),1/MMULT((IF($A$2:$A$15=$F2,$D$2:$D$15)=
TRANSPOSE(IF($A$2:$A$15=$F2,$D$2:$D$15)))+0,(ROW($A$2:$A$15)>0)+0))
Note this is an array formula, so you have to press Ctrl+Shift+Enter after typing this formula instead of just Enter.
See working example below. This formula is in cell G2 and dragged down.
My excel sheet looks like this:
Name C.p Value
a 1 1.75
b 1 2.35
c 1 1.32
d 1 2.45
a 2 2.7
b 2 1.85
c 2 1.9
d 2 2.6
a 3 3.2
b 3 4.5
c 3 9.2
d 3 5.01
Like this 4~5 names 50 ~ 60 check points and values at those check points
I want the excel to look like
C.p a b c d
1 1.75 2.35 1.32 2.45
2 2.7 1.85 1.9 2.6
3 3.2 4.5 9.2 5.01
Here C.p is check point. it is not always 1 2 3 .. it changes values form sheet to sheet
Could Some one help with the code
thank you
If that is the only thing you want to do,You can do it quickly by pivot table in excel itself. You will get some extra columns like Grand Total Which you can remove. As far as effort for removing the unwanted columns to the code it will be quite less.
see the below pic.