My data looks like this:
It is grouped by "name"
name star atm food foodcp drink drinkcp clean cozy service
___Backyard Jr. (__Xinyi) 4 4 4 4 4 0 4 0 0
___Backyard Jr. (__Xinyi) 3 0 3 0 3 0 0 0 3
___Backyard Jr. (__Xinyi) 4 0 0 0 4 0 0 0 0
___Backyard Jr. (__Xinyi) 3 0 0 0 0 0 0 3 3
I want to calculate the mean of all columns except for name, which will ignore the "0" and it will be done within groups. How can I do it?
I've tried use
df.groupby('name',as_index=False).mean()
but it dose calculate the "0".
Thank you for your help!!
You can first replace all the zeros by NaN:
df = df.replace(0, np.nan)
These nan values will be excluded from your mean.
I am trying to use offset function in excel to dynamically calculate sales since launch of products (3 months after, 6 months after etc.). For eg. for item 1 first 3 months of sale is 2557+10000+14487= 27044 and similarly for item 2 first 3 months sale will be 2557+11853+14487=28897
Any guidance on this is super appreciated!!
Items
Item1
Item2
Jan-20
0
0
Feb-20
0
0
Mar-20
0
0
Apr-20
0
0
May-20
0
2557
Jun-20
0
11853
Jul-20
0
14487
Aug-20
0
11375
Sep-20
0
10938
Oct-20
0
10842
Nov-20
0
15132
Dec-20
0
19820
Jan-21
2557
20726
Feb-21
10000
25072
Mar-21
14487
28897
Apr-21
11375
28665
May-21
10938
42358
Jun-21
10842
25619
Jul-21
15132
20575
Aug-21
19820
23315
Sep-21
20726
21346
Oct-21
25072
19377
Yes, avoid offset. You could use index/match for example:
=SUM(INDEX(B:B,MATCH(0,B:B)+1):INDEX(B:B,MATCH(0,B:B)+3))
I have a schedule that my team fills out daily in a google sheet. On a seperate tab, I would like a running count per day per schedule code per agent.
Linking a sample spreadsheet here. In this example, I'm trying to input a countif that returns
2019-01-27 T 5 6 0 4
2019-01-27 C 3.5 0 0 7
2019-01-27 LC 0 0 0 0
2019-01-27 S 0 0 0 0
2019-01-27 L 0.5 0 0 1
2019-01-27 M 0.5 0 0 1
2019-01-27 SP 0 0 0 0
2019-01-27 U 0 0 0 0
2019-01-27 MCX 2 0 0 2
2019-01-27 OCX 0 0 0 0
2019-01-27 TR 0 0 0 0
But I cannot for the life of me get a countifs function to work. Any help is much appreciated!
https://docs.google.com/spreadsheets/d/1gp0ZrcYLJfEnUHxgxagAl99X_MCjEIdvwFyfSdGngSE/edit?usp=sharing
Combine INDIRECT with MATCH:
=COUNTIF(INDIRECT("'Mon 1/27'!F"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)&":AG"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)),$B2)
INDIRECT
MATCH
Here is how it works:
MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0) will search the row number of the agent, referenced to cell A1
INDIRECT("'Mon 1/27'!A"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)&":AG"&MATCH(D$1,'Mon 1/27'!$A$1:$A$5,0)) will return a range referenced always to columns F and AF but with the row number returned in step 1, ie, F3:AG3,F4:AG4, and son.
COUNTIF will just count the criteria in the range from step 2.
Hope this helps.
IMPORTANT: In the expected output you posted, the MCX result for Barack Obama is 2, but my formula gets 4. Are you sure your output is right?
I have this issue in excel where I want to delete 0 and re-stack the rows.
Problem:
0 0 1 2 3
0 0 0 1 0
0 2 3 0 1
2 5 3 0 0
The desired result would be
1 2 3
1 0
2 3 0 1
2 5 3 0 0
Any suggestions?
This will create a range from the first non 0 to the end and then the outer INDEX will return them in order as it is dragged across.
=IFERROR(INDEX(INDEX($A1:$E1,AGGREGATE(15,7,COLUMN($A1:$E1)/($A1:$E1<>0),1)):$E1,,COLUMN(A:A)),"")
Just for the sake of giving alternatives:
Formula in A6 translates to:
=IFERROR(INDEX($A1:$E1,,MATCH(TRUE,INDEX($A1:$E1>0,0),0)+COLUMN()-1),"")
Dragged down and sideways.
I've set up Names with the intention of using them to return data ranges for a line chart. The X values are "GI", "IE" and "EE". The Y value is "DATE".
However, my "DATE" and "GI" names are returning "#VALUE!" errors - whereas IE and EE are not.
So far, I have found that this error occurs when the height value (CountIf below) is more than 1.
The cell range, and beyond to 2000-and-something, are dynamically generated from user selections to form a Date Range. Ergo the use of CountIf rather than CountA.
Any help would be much appreciated. This is the last leg of a difficult workbook!
DATE:
=OFFSET(Graph!$B$8,0,0,COUNTIF(Graph!$B$8:$B$2927,">"&0)-1)
GI:
=OFFSET(Graph!$C$8,0,0,COUNTIF(Graph!$C$8:$C$2927,">"&0)-1)
IE:
=OFFSET(Graph!$D$8,0,0,COUNTIF(Graph!$D$8:$D$2927,">"&0)-1)
EE:
=OFFSET(Graph!$E$8,0,0,COUNTIF(Graph!$E$8:$E$2927,">"&0)-1)
Information:
B C D E
7 DATE GI IE EE
8 25/04/2011 0 0 0
9 26/04/2011 0 0 0
10 27/04/2011 0 0 0
11 28/04/2011 0 0 0
12 29/04/2011 0 0 0
13 30/04/2011 0 0 0
14 01/05/2011 0 0 0
15 02/05/2011 0 0 0
16 03/05/2011 0 0 0
17 04/05/2011 0 0 0
18 05/05/2011 0 0 0
19 06/05/2011 0 0 0
20 07/05/2011 0 0 0
21 08/05/2011 0 0 0
22 09/05/2011 0 0 0
23 10/05/2011 18000 0 0
24 11/05/2011 18000 0 0
25 12/05/2011 18000 0 0
26 13/05/2011 18000 0 0
27 14/05/2011 18000 0 0
28 15/05/2011 18000 0 0
29 16/05/2011 18000 0 0
30 17/05/2011 18000 0 0
31 18/05/2011 18000 0 0
32 19/05/2011 18000 0 0
33 20/05/2011 18000 0 0
34 21/05/2011 18000 0 0
35 22/05/2011 18000 0 0
This formula should create the correct named Range for date:
=OFFSET(Sheet1!$B$8,0,0,MATCH(Sheet1!$D$4,Sheet1!$B$8:$B$2927,0),1)
For GI:
=OFFSET(Sheet1!$B$8,0,1,MATCH(Sheet1!$D$4,Sheet1!$B$8:$B$2927,0),1)
For IE:
=OFFSET(Sheet1!$B$8,0,2,MATCH(Sheet1!$D$4,Sheet1!$B$8:$B$2927,0),1)
For EE:
=OFFSET(Sheet1!$B$8,0,3,MATCH(Sheet1!$D$4,Sheet1!$B$8:$B$2927,0),1)
(D4 contains the end date dropdown.)
In the data selection for the graph, it is important to write the named Range including the sheet it's on, e.g.: =Sheet1!nrDate instead of just =nrDate.
Please let me know if this works for you.
So based on your data, an going a slightly different route than offset (offset route should work) I used the index route.
for the x axis I used
=INDEX($B$9:$B$36,MATCH($C$5,$B$9:$B$36,0)):INDEX($B$9:$B$36,MATCH($D$5,$B$9:$B$36,0))
I used a defined name of X_axis
for the y axis I used
=INDEX($C$9:$C$36,MATCH($C$5,$B$9:$B$36,0)):INDEX($C$9:$C$36,MATCH($D$5,$B$9:$B$36,0))
I used a define name of Y_axis. For your second series on the Y axis, you would need to change the reference range from C9:C36, to the appropriate column that is lined up with your dates.
When defining the series, I had to use the workbook name in conjunction with the named range. so series data looked like this:
Proof of Concept