Excel match/index by column pair? - excel

I am definitely a beginner when it comes to advanced Excel syntax. I tried searching for an answer to my question, but I may be too inexperienced to know how to look. Also possible I misspecified my title. Apologies if this has been answered previously.
Say I have the following 3 columns
A B C
1 Alabama Alabama Red
2 Alaska Wyoming Blue
3 Arizona Alaska Yellow
4 Arkansas Florida Green
5 California Arkansas Black
And I want to produce a list of same-row B/C pairs that have B values equal to A values:
D E
1 Alabama Red
2 Alaska Yellow
3 Arkansas Black
How can I do this?
Thank you thank you thank!

Related

How to Replace Multiple String in a Data frame Using Python

I have a data frame with 73k rows, and here's the following sample data :
Index Customers' Name States
0 Alpha Oregon
1 Alpha Oregon
2 Bravo Utah
3 Bravo Utah
4 Charlie Alabama
5 Charlie Alabama
6 Alpha Oregon
7 Alpha Oregon
8 Bravo Utah
The data have a unique value but I am not allowed to delete or remove it because it's needed or mandatory for my research. On the other hand, I would like to change the customers' names with some specific pseudocode so the result can look like this :
Index Customers' Name States
0 z1 Oregon
1 z1 Oregon
2 z2 Utah
3 z2 Utah
4 z3 Alabama
5 z3 Alabama
6 z1 Oregon
7 z1 Oregon
8 z2 Utah
I'm still a beginner, learning Python for around 3 months. So, how can I change this in a 'bulky' way remembering that I have 73k rows like this? I assume that it must be executed using a looping ('For'). I already tried, but I can't wrap up this well. Please help me finish/solve this.
You can use .groupby() with .ngroup():
df["Customers' Name"] = "z" + (
df.groupby("Customers' Name").ngroup() + 1
).astype("str")
print(df)
Prints:
Customers' Name States
0 z1 Oregon
1 z1 Oregon
2 z2 Utah
3 z2 Utah
4 z3 Alabama
5 z3 Alabama
6 z1 Oregon
7 z1 Oregon
8 z2 Utah

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)

Returning the last item in a subset with excel formula

In this example I would like to mark any customer that has bought a pen most recently(or bottom of the list). I have my data sorted by CustomerID and ServiceDate with the most recent as the last. I would like to be able to mark all of the customer’s transactions only if the last purchase was a pen (333).
I have been trying formulas with COUNTA but, not sure how to do it when relying on a subset of data.
=INDEX(C:C,COUNTA(C:C))
This will give me the last value in a column.
Customer ID Custmer Name Item Number Item Name Date Desired Results
1 Bob 222 Paper 1/1/2016 X
1 Bob 111 Tape 1/1/2017 X
1 Bob 333 Pen 1/1/2018 X
4 Greg 333 Pen 1/1/2015
4 Greg 111 Tape 1/1/2016
6 Chris 111 Tape 1/1/2015 X
6 Chris 333 Pen 1/1/2018 X
8 Luke 333 Pen 1/1/2013
8 Luke 333 Pen 1/1/2014
8 Luke 222 Paper 1/1/2015
8 Luke 111 Tape 1/1/2016
8 Luke 111 Tape 1/1/2018
9 Tom 333 Pen 1/1/2013 X
You can do this by creating an additional column. The additional column will find all customers whose last purchase was a pen using this formula: =IF(AND(C2=333,B2<>B3),B2,"").
The next column will give you your desired output: =IF(OR(B2=$F$4,B2=$F$8,B2=$F$14),"X","").
Thanks to joe I was able to figure this one out.
I still had to make another column.
I put this in column F.
=IF(AND(C2=333,B2<>B3),1,"")
Then in column G.
=IF(AND(COUNTIFS(A:A,A2,F:F,1)=1),"Yes","")
This worked great.

Combining multiple values attached to the same variable in Excel

I need to add multiple values related to the same variable into one single entry. Here is what my worksheet looks like:
ColA ColB ColC
Onion Ounces 12
Onion Ounces 6
Carrot Kilo 3
Basil Grams 25
Carrot Kilo 6
Basil Cups 3
Here is what I am trying to figure out how to do:
ColA ColB ColC
Onion Ounces 12
Onion Ounces 6
Carrot Kilo 3
Basil Grams 25
Carrot Kilo 6
Basil Cups 3
__________________
Onion Ounces 18
Carrot Kilo 9
Basil Grams 25
Basil Cups 3
*If colA matches (both entries are 'Basil'), but colB doesn't match (one entry is 'ounces' and one is 'cups') it needs to have separate entries.
I'm very new to excel and not even sure how to phrase this question correctly, so my apologies if this has been answered many times before!
Thank you so much for your help!
Use Query:
=QUERY(A1:C6,"Select A,B,Sum(C) group by A,B")

Excel Finding What Place a Value Comes In

I am trying to find a way to get which place a certain value comes in in a range of other values. Or another way to look at it is I want to turn the SMALL function inside out. The SMALL function looks like this, "=SMALL(array, k)" where it looks for the k place in an array. I need the find what the k is. I hope that makes sense, but if not here is one more example.
A B C D
1 Kate 12.25 =PLACE($B$1:$B$13,B1) 4
2 Cindy 15.80 =PLACE($B$1:$B$13,B2) 10
3 Mark 11.85 =PLACE($B$1:$B$13,B3) 3
4 Thomas 12.98 =PLACE($B$1:$B$13,B4) 5
5 George 13.58 =PLACE($B$1:$B$13,B5) 7
6 Kim 14.52 =PLACE($B$1:$B$13,B6) 9
7 Tim 11.54 =PLACE($B$1:$B$13,B7) 2
8 Frank 12.99 =PLACE($B$1:$B$13,B8) 6
9 Fran 17.85 =PLACE($B$1:$B$13,B9) 11
10 Caroline 14.25 =PLACE($B$1:$B$13,B10) 8
11 Alex 19.20 =PLACE($B$1:$B$13,B11) 12
12 Lilly 25.20 =PLACE($B$1:$B$13,B12) 13
13 Peter 11.22 =PLACE($B$1:$B$13,B13) 1
Also I can easily do it with VBA, but I do not want to. I want to do it in cell and I do not want to have to sort them first.
RANK function does this, i.e. in your case this formula in row 1 copied down
=RANK(B1,B$1:B$13,1)
The 1 at the end indicates the order of ranking (ascending here). Leave that out and you get descending ranking

Resources