How to list row headers from matrix based on binary value (Excel)? - excel

I would like to extract/list from a matrix the row headers based on binary values and depending on the column. Basically FROM something like this:
Country Product1 Product2 Product3
Germany 1 0 1
France 1 1 0
Spain 0 1 0
Italy 1 0 1
Belgium 0 1 0
OBTAIN something like this:
Product1 Product2 Product3
Germany France Germany
France Spain Italy
Italy Belgium
So basically list the values based on column and binary value.
Better if no VBA is involved.
Any suggestion is welcome!

Assuming your data is in a table named Table1, for Office 365:
=T(SORT(IF(Table1[Product1],Table1[[Country]:[Country]])))
and use the fill handle to drag right.

Related

Extract the mapping dictionary between two columns in pandas

I have a dataframe as shown below.
df:
id player country_code country
1 messi arg argentina
2 neymar bra brazil
3 tevez arg argentina
4 aguero arg argentina
5 rivaldo bra brazil
6 owen eng england
7 lampard eng england
8 gerrard eng england
9 ronaldo bra brazil
10 marria arg argentina
from the above df, I would like to extract the mapping dictionary that relates the country_code with country columns.
Expected Output:
d = {'arg':'argentina', 'bra':'brazil', 'eng':'england'}
Dictionary has unique keys, so is possible convert Series with duplicated index by column country_code:
d = df.set_index('country_code')['country'].to_dict()
If there is possible some country should be different per country_code, then is used last value per country.

In Excel how can a formula verify whether the column location or column element has taken the correct data from its header name?

The Input data
in sheet1
and
the output calculated in sheet2
Now the sheet1 data can be changed by the user for input, so now columns 'Units1' & 'Units2' may not be placed at the same address that are in columns 'C' and 'D' respectively, so suppose a new user will input the data in which 'Avocado' and 'Banana' are in columns C & D , then the 'Output' calculation in Sheet2 will be incorrect because we always want to use Units1 & Units2 for calculation.
How to fix this, so that every time the data is input the formula checks whether the correct columns have been taken for calculation or not?
Is there a way to use INDEX or family of LOOKUP functions or any other function for this.
Maybe by a creating a new sheet and making a table of Indexes which refer to (or point to) the column names of Data sheet
Location
Dates
Units1
Units2
Avocado
Banana
New York
05-01-18
10
12
1
2
Los Angeles
02-02-18
20
23
1
2
Chicago
08-03-18
30
34
1
2
Houston
05-04-18
40
45
1
2
Phoenix
02-05-18
50
56
1
2
Philadelphia
08-06-18
60
67
1
2
San Antonio
05-07-18
70
78
1
2
San Diego
02-08-18
80
89
1
2
Dallas
08-09-18
90
99
1
2
San Jose
05-10-18
100
112
1
2
Use INDEX/MATCH:
=INDEX(2:2,1,MATCH("Units2",$1:$1,0))/INDEX(2:2,1,MATCH("Units1",$1:$1,0))

Question about excel columns csv file how to combine columns

I got a quick question I got a column like this
the players name and the percentage of matches won
Rank
Country
Name
Matches Won %
1 ESP ESP Rafael Nadal 89.06%
2 SRB SRB Novak Djokovic 83.82%
3 SUI SUI Roger Federer 83.61%
4 RUS RUS Daniil Medvedev 73.75%
5 AUT AUT Dominic Thiem 72.73%
6 GRE GRE Stefanos Tsitsipas 67.95%
7 JPN JPN Kei Nishikori 67.44%
and I got another data like this ACES PERCENTAGE
Rank
Country
Name
Ace %
1 USA USA John Isner 26.97%
2 CRO CRO Ivo Karlovic 25.47%
3 USA USA Reilly Opelka 24.81%
4 CAN CAN Milos Raonic 24.63%
5 USA USA Sam Querrey 20.75%
6 AUS AUS Nick Kyrgios 20.73%
7 RSA RSA Kevin Anderson 17.82%
8 KAZ KAZ Alexander Bublik 17.06%
9 FRA FRA Jo Wilfried Tsonga 14.29%
---------------------------------------
85 ESP ESP RAFAEL NADAL 6.85%
My question is can I make my two tables align so for example I want to have
my data based on matches won
So I have for example
Rank Country Name Matches% Aces %
1 ESP RAFAEL NADAL 89.06% 6.85%
Like this for all the player
I agree with the comment above that it would be easiest to import both and to then use XLOOKUP() to add the Aces % column to the first set of data. If you import the first data set to Sheet1 and the second data set to Sheet2 and both have the rank in Column A , your XLOOKUP() in Sheet 1 Column E would look something like:
XLOOKUP(A2, Sheet2!A:A, Sheet2!D:D)

python: groupby - function called when grouping

All I would like to do a groupby and call a function at the same time.
Here is the function
def dollar_wtd_two(DF, kw_param, kw_param2):
return np.sum(DF[kw_param] * DF[kw_param2]) / DF[kw_param2].sum()
The function dollar_wtd_two has 3 parameters DF (the dataframe) and columns names of the same dataframe DF. Conceptually here what I would like to do:
DF.groupby(['prime_broker_id', 'country_name'],
as_index=False).agg({"notional_current": np.sum, "new_column":dollar_wtd_two(DF,
kw_param, kw_param2) })
Basically the groupby would do simple operations like sum or average and also more involved operations where I would call functions similar to dollar_wtd_two
Here is how the output of DF would like without the "new_column"
DF.groupby(['prime_broker_id', 'country_name'],
as_index=False).agg({"notional_current": np.sum })
Output 1:
prime_broker_id country_name notional_current
0 BARCAP AUSTRIA 2.616735e+07
1 BARCAP BELGIUM 6.327196e+07
2 BARCAP DENMARK 1.286309e+07
3 BARCAP FINLAND 4.181843e+07
4 BARCAP FRANCE 1.579292e+08
5 BARCAP GERMANY 2.653451e+08
6 BARCAP IRELAND 1.037968e+07
I am not able to show the output of DF with "new_column":dollar_wtd_two(DF, kw_param, kw_param2). However individually the output of dollar_wtd_two(DF, kw_param, kw_param2) should look like this:
Output 2:
prime_broker_id country_name
BARCAP AUSTRIA 25.009402
BELGIUM 25.083404
DENMARK 25.000000
FINLAND 25.034493
FRANCE 25.000000
GERMANY 25.007943
IRELAND 25.000000
ISRAEL 399.242997
The idea is to combine Output 1 and Output 2 in one operation. Please let me if it is unclear.
Any help is more than welcome
Thanks a lot

Excel Update column based on another column from another sheet

I've an excel with 2 sheets
In One sheet I've data like below
ID ID1 Name
1 101 ABC
2 202 XYZ
3 303 MNP
In Sheet2 I've data like below
ID ADD
1 LONDON
2 USA
3 CANADA
Now I need add one more column in sheet2 and want ID2 corresponding to ID1 from sheet1.
Like
ID ADD ID2
1 LONDON 101
2 USA 202
3 CANADA 303
Please help.
Use INDEX(MATCH()):
=INDEX(Sheet1!B:B,MATCH(A2,Sheet1!A:A,0))

Resources