Excel graphic with 2 x-as variables en 2 y-as variables - excel

How can I get a chart in Excel with:
x-as is equal to the combination of JM and location
y-as are the %-values from Occupied next or on top of empty
So in month 201801 I can see the 2 (or more max 30) locations with both %-values
next to month 201802 and so on.
(Eventualy I can set a trendline on Occupied)
Hopefully my question is clear
The is a short example table:
JM location Occupied% Empty%
201801 A 80 20
201801 B 54 46
201802 A 64 36
201802 B 89 11
201803 A 50 50
201803 B 89 11
201804 A 99 1
201804 B 67 33
201805 A 100 0
201805 B 78 22
201806 A 98 2
201806 B 86 14
201807 A 93 7
201807 B 58 42
201808 A 67 33
201808 B 79 21
201809 A 67 33
201809 B 57 43
201810 A 98 2
201810 B 97 3
201811 A 65 35
201811 B 68 32
201812 A 87 13
201812 B 99 1

Very easy with a pivottable. Select Insert, Pivottable and drag JM to the row field area and Location to the column field area and Occupied to the sigma area. Then insert a line pivot chart.

Related

In Excel How can I sum (or perform any operation) total sum values of various columns when the column name is mentioned in a cell?

So I have a set of Data having 6 columns under different headers.
In sheet 2 we select some variables from Data sheet (to perform sum operation in this case).
Whenever the user inputs some or all variables (Fruits, Veggies, Drinks, Snacks, Vegan, Dairy)from Data (sheet1) in to sheet 2 for items_chosen under Formula column (e.g Veggies + Drinks + Vegan) , then the output column(sheet 2) should display sum total of these selected columns, under Results.
example: We chose, (Veggies + Snacks + Dairy) ;
Now total of each of these columns are 1222(veggies) , 1927(snacks) , 328(dairy) ;
So in sheet 2 under result ,it should display = 3447 which is the sum total of [1222(veggies) + 1927(snacks) + 328(dairy)]
I know we can use Indirect function in excel but how can I take input from what is written in Choose Variables here column in sheet 2
Sample Data:
Fruits
Veggies
Drinks
Snacks
Vegan
Dairy
1
3
9
7
8
4
23
31
26
34
71
45
45
51
93
72
353
41
67
134
56
81
431
155
89
42
242
457
513
19
111
61
574
541
54
15
133
46
426
156
135
17
155
522
264
166
351
18
177
332
624
413
54
14
Output:
Label
Choose Variables here
Output
Result
Items_chosen
Veggies + Snacks + Dairy
Result of Items_chosen
Try below formula.
=SUMPRODUCT((A2:F10)*(ISNUMBER(SEARCH(A1:F1,I3))))

Pandas: how to drop the lowest 5th percentile for each indexed group?

I have the following issue with python pandas (I am relatively new to it): I have a simple dataset with a column for date, and a corresponding column of values. I am able to sort this Dataframe by date and value by doing the following:
df = df.sort_values(['date', 'value'],ascending=False)
I obtain this:
date value
2019-11 100
2019-11 89
2019-11 87
2019-11 86
2019_11 45
2019_11 33
2019_11 24
2019_11 11
2019_11 8
2019_11 5
2019-10 100
2019-10 98
2019-10 96
2019-10 94
2019_10 94
2019_10 78
2019_10 74
2019_10 12
2019_10 3
2019_10 1
Now, what I would like to do, is to get rid of the lowest fifth percentile for the value column for EACH month (each group). I know that I should use a groupby method, and perhaps also a function:
df = df.sort_values(['date', 'value'],ascending=False).groupby('date', group_keys=False).apply(<???>)
The ??? is where I am struggling. I know how to suppress the lowest 5th percentile on a sorted Dataframe as a WHOLE, for instance by doing:
df = df[df.value > df.value.quantile(.05)]
This was the object of another post on StackOverflow. I know that I can also use numpy to do this, and that it is much faster, but my issue is really how to apply that to EACH GROUP independently (each portion of the value column sorted by month) in the Dataframe, not just the whole Dataframe.
Any help would be greatly appreciated
Thank you so very much,
Kind regards,
Berti
Use GroupBy.transform with lambda function for Series with same size like original DataFrame, so possible filter by boolean indexing:
df = df.sort_values(['date', 'value'],ascending=False)
q = df.groupby('date')['value'].transform(lambda x: x.quantile(.05))
df = df[df.value > q]
print (df)
date value
4 2019_11 45
5 2019_11 33
6 2019_11 24
7 2019_11 11
8 2019_11 8
14 2019_10 94
15 2019_10 78
16 2019_10 74
17 2019_10 12
18 2019_10 3
0 2019-11 100
1 2019-11 89
2 2019-11 87
10 2019-10 100
11 2019-10 98
12 2019-10 96
You could create your own function and apply it:
def remove_bottom_5_pct(arr):
thresh = np.percentile(arr, 5)
return arr[arr > thresh]
df.groupby('date', sort=False)['value'].apply(remove_bottom_5_pct)
[out]
date
2019-11 0 100
1 89
2 87
3 86
4 45
5 33
6 24
7 11
8 8
2019-10 10 100
11 98
12 96
13 94
14 94
15 78
16 74
17 12
18 3
Name: value, dtype: int64

Excel - calculate average of values in one column based on another grouping column. The number of rows is not constant per group

Two columns, one with ID and one with values. I want to calculate average per ID. The number of rows per ID is not constant. What i have:
ID Value
1 22
1 31
1 34
1 23
1 31
34 67
34 65
34 55
12 44
12 46
12 43
12 35
I want a formula which will calculate third column:
ID Value Average per id
1 22 28.2
1 31 28.2
1 34 28.2
1 23 28.2
1 31 28.2
34 67 62.3
34 65 62.3
34 55 62.3
12 44 42.0
12 46 42.0
12 43 42.0
12 35 42.0
I have tried AVERAGEIF function but i cant figure it out.
Just use these formulas:
=AVERAGEIF(A:A,A2,B:B)
or
=SUMIF(A:A,A2,B:B)/COUNTIF(A:A,A2)

Finding the median of a range of values selected using vlookup

Column A are dates and B & C are Measurements
Dates Measurements
1 56 15
2 45 25
3 62 76
4 15 42
5 165 56
6 16 79
7 45 46
8 47 79
9 24 47
10 12 14
11 147 47
12 195 19
13 443 79
14 642 43
15 462 75
16 156 87
17 794 49
Start Date:2
Measurement:45
Code used to solve for the measurement
=VLOOKUP(B21,A2:C18,2,FALSE)
end date:14
Measure:642
=VLOOKUP(B22,A2:C18,2,FALSE)
I used vlookup to find me the values that I desire, but now I want to find the median values of that range from the start to end date in each column.
How can I code it so that once it selects the values, it can select the whole range and find the median values?
Since your column A values are ordered ascendingly, we can use the very efficient:
=MEDIAN(INDEX(B2:B18,MATCH(B21,A2:A18)):INDEX(B2:B18,MATCH(B22,A2:A18,0)))
Regards

How to Transpose the data in Pivot table?

I have a source content as shown below
Name Age Month Maths Science Physics
John 21 1 80 88 76
John 21 2 89 99 78
John 21 3 76 76 89
John 21 4 78 78 90
John 21 5 88 89 96
Sara 22 1 76 76 89
Sara 22 2 78 78 90
Sara 22 3 88 89 96
Sara 22 4 76 76 89
Sara 22 5 78 78 90
and i am looking to create a pivot table in excel something like this.
Name John
Age All
Month 1 2 3 4 5
Maths 80 89 76 78 88
Science 88 99 76 78 89
Physics 76 78 89 90 96
Is this possible? Thanks for looking
On your destination sheet, select an empty range with the correct number of columns and rows.
On the Formulas ribbon, select Insert Function and then specify All Functions in the dialog box.
In the list of functions, select Transpose, and give the entire range from the source sheet that you wish to transpose;
Click OK - your data range should now be transposed on the destination sheet
Select the entire destination range and then on the Data Ribbon select Auto-Filter.
You can now filter on any of the columns as desired.
In the above answer, at step 3, you need to make the TRANSPOSE function an array formula. In other words, hit "C-S-E" -- Control-Shift-Enter. Then your function is surrounded by curly brackets indicating it is an array function.

Resources